A horrifying globalThis polyfill in JavaScript
There, you can access the global :
Furthermore, sloppy mode functions always have their set to the global , so even if you cannot run your code in the global scope, you could still get access to the global as follows in sloppy mode:
However, the top-level value is in JavaScript modules, and is within strict mode functions, so this approach doesn’t work there. It seems like it should be possible to combine the above techniques into a single polyfill, like so:
But alas, this doesn’t work in strict mode functions or within JavaScript modules in non-browser environments (except those with support). A JavaScript engine could use such an object as the global without violating the spec, in which case the above code snippet still wouldn’t work (and indeed, Internet Explorer 7 did something like that!)
Source: mathiasbynens.be