Naivete Precedes Misrepresentation
    Wondering what’s next for npm?Check out our public roadmap! »


    1.0.2 • Public • Published

    The Global Object

    npm install
    Travis Build Status CircleCI Build Status Build Status CircleCI Dependencies Status Known Vulnerabilities Downloads License

    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:

    Problems with Function()

    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 self, window or global 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 called self or 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 Array and setInterval equal to the global ones

    The Array and 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.


    Rafał Pocztarski
    Follow on GitHub Follow on Twitter
    Follow on Stack Exchange


    MIT License (Expat). See for details.


    npm i the-global-object

    DownloadsWeekly Downloads






    Unpacked Size

    8.93 kB

    Total Files


    Last publish


    • avatar