Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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