globalThis polyfill
Let's polyfill globalThis, like https://github.com/es-shims/globalThis/blob/main/polyfill.js
by David Iglesias
HTML
<p>
Look at the JS console!
</p>
JavaScript
// Simulate old browser
let defaultGlobalThis = globalThis;
globalThis = null;
console.log(globalThis); // null
// Apply shim
(typeof globalThis!="object"||!globalThis||globalThis.Math!==Math||globalThis.Array!==Array)&&(typeof self<"u"?globalThis=self:typeof window<"u"?globalThis=window:globalThis=Function("return this")());
// Did it work?
console.log(globalThis); // not null (Window)
console.log(globalThis === defaultGlobalThis); // should be true