Last active
January 2, 2020 15:20
-
-
Save rauschma/bb3e5047a461961cfe19a1335b772d7c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Based on: https://mathiasbynens.be/notes/globalthis | |
export const getGlobalThis = () => { | |
if (typeof globalThis !== 'undefined') return globalThis; | |
if (typeof self !== 'undefined') return self; | |
if (typeof window !== 'undefined') return window; | |
if (typeof global !== 'undefined') return global; | |
return eval.call(undefined, 'this'); | |
}; | |
export const installGlobalThis = () => { | |
if (typeof globalThis === 'undefined') { | |
const gt = getGlobalThis(); | |
gt['globalThis'] = gt; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment