Skip to content

Instantly share code, notes, and snippets.

@Cologler
Created July 5, 2020 05:54
Show Gist options
  • Save Cologler/a85a89bcdc9445148ce213a3d31eeeb2 to your computer and use it in GitHub Desktop.
Save Cologler/a85a89bcdc9445148ce213a3d31eeeb2 to your computer and use it in GitHub Desktop.
get global object on node/browser
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