Created
July 5, 2020 05:54
-
-
Save Cologler/a85a89bcdc9445148ce213a3d31eeeb2 to your computer and use it in GitHub Desktop.
get global object on node/browser
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
function getGlobal() { | |
if (typeof globalThis !== 'undefined') { | |
return globalThis; | |
} else if (typeof window !== 'undefined') { | |
return window; // browser | |
} else if (typeof global != 'undefined') { | |
return global; // node | |
} else { | |
throw Error('unknown'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment