/** * Returns the global object. * Works even inside ES6 modules. */ function getGlobalObject() { // Workers don’t have `window`, only `self` if (typeof self !== 'undefined') { return self; } if (typeof global !== 'undefined') { return global; } // Not all environments allow eval and Function // Use only as a last resort: return new Function('return this')(); }