Skip to content

Instantly share code, notes, and snippets.

@krackers
Forked from bingo347/globalThis-polyfill.js
Created February 23, 2023 22:08
Show Gist options
  • Save krackers/bc338dc4662bd1da72a5675ae796a5ed to your computer and use it in GitHub Desktop.
Save krackers/bc338dc4662bd1da72a5675ae796a5ed to your computer and use it in GitHub Desktop.
globalThis simple polyfil
(() => {
const isNotUndefined = typeofResult => typeofResult !== 'undefined';
if(isNotUndefined(typeof globalThis) && globalThis.globalThis === globalThis) { return; }
const g = (isNotUndefined(typeof window) && window)
|| (isNotUndefined(typeof global) && global)
|| (isNotUndefined(typeof self) && self)
|| Function('return this')();
g.globalThis = g;
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment