Created
June 7, 2020 10:02
-
-
Save bisubus/c78c8d770b3ca577099b88c1f15597e2 to your computer and use it in GitHub Desktop.
Cross-platform global variable detection with fallbacks
This file contains hidden or 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
// self is window proxy in IE<=10, eval handles this | |
var _global = (function () { try { return Function('return this')() } catch (e) {} })() // browsers without CSP, Node | |
|| typeof globalThis !== 'undefined' && globalThis // new and polyfilled browsers/workers CSP, newer Node with broken eval | |
|| typeof self !== 'undefined' && self // old browsers/workers with CSP | |
|| typeof global !== 'undefined' && global // old Node with broken eval | |
|| typeof window !== 'undefined' && window; // fallback for exotic environments |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment