Skip to content

Instantly share code, notes, and snippets.

@Goku-kun
Last active March 21, 2021 04:48
Show Gist options
  • Save Goku-kun/6897d81ada45692dd11aefa67434b55b to your computer and use it in GitHub Desktop.
Save Goku-kun/6897d81ada45692dd11aefa67434b55b to your computer and use it in GitHub Desktop.
This is a reliable cross environment global object reference polyfill which allows access to the global object of any JS environment using the identifier called theGlobalScopeObject.
const theGlobalScopeObject =
(typeof globalThis != "undefined") ? globalThis :
(typeof global != "undefined") ? global :
(typeof window != "undefined") ? window :
(typeof self != "undefined") ? self :
(new Function("return this"))();
// globalThis is a standardized object as of ES2020 which can be used to access the global scope.
// To find the reference of the global of any environment, the following script can be used:
var globalObject = (new Function("return this"))();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment