Skip to content

Instantly share code, notes, and snippets.

@DavidWells
Created July 6, 2020 04:02
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save DavidWells/54d76ec16f1c4b3a2a94fd8777ccc855 to your computer and use it in GitHub Desktop.
Save DavidWells/54d76ec16f1c4b3a2a94fd8777ccc855 to your computer and use it in GitHub Desktop.
function getGlobalThis() {
if (typeof globalThis !== 'undefined') return globalThis
if (typeof global !== 'undefined') return global
if (typeof self !== 'undefined') return self /* eslint-disable-line no-restricted-globals */
if (typeof window !== 'undefined') return window
if (typeof this !== 'undefined') return this
return {} // should never happen
}
const globalContext =
(typeof self === 'object' && self.self === self && self) ||
(typeof global === 'object' && global.global === global && global) ||
this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment