the-global-object1.0.2 • Public • Published
The Global Object
Returns the global object in Node or in the browser, including the web worker.
Hopefully it will no longer be needed when the TC39 global proposal is implemented, see:
The only reliable way to get the global object is:
const theGlobalObject = Function'return this';
but it breaks the Chrome App Content Security Policy, see:
How this module works
This module checks to see if there is a global variable called
and returns the first one that has a reference to itself with the same name,
as a real global object would, with some additional checks.
This is important to not return a wrong object if there happens to be a global variable
window defined, but it's not the global object itself.
This module does the following checks to make sure that:
- the object has a circular reference to itself with the correct name
- the object has properties
setIntervalequal to the global ones
setInterval are chosen arbitrarily as examples of names that are
unlikely to be there by accident and that are guaranteed to be present
on the global object as required by the language specification.
For any bug reports or feature requests please post an issue on GitHub.
MIT License (Expat). See LICENSE.md for details.