Closed rictic closed 5 years ago
The best version I've got:
var polyfilledGlobalThis =
this !== undefined ? this :
typeof window === 'object' ? window :
typeof global === 'object' ? global :
undefined /* or maybe throw? */;
Function(‘return this’)()
absolutely works in an ES Module context.
Ether way, proposal repo polyfills aren’t for production use. Use https://npmjs.com/globalthis
When running as an ES Module, the global
this
is always undefined.