$ npm install @offirmo/globalthis-ponyfill
This is a trivial TypeScript-compatible globalThis ponyfill.
import { getGlobalThis } from '@offirmo/globalthis-ponyfill'
// typed access
declare global {
var foo: number
}
const globalThis = getGlobalThis()
globalThis.foo = 42
// untyped access
const globalThis = getGlobalThis<any>()
globalThis.bar = 42
globalThis is a TC-39 proposal
which is already supported by Firefox and Chrome.YES I had a look at ljharb/globalThis 's implementation (MIT) and started my implementation from it! Thanks a lot and all credits due!
About the proposed implementation here: https://mathiasbynens.be/notes/globalthis we can't use it: it creates a polyfill, not a ponyfill. However I took a line from the "naive implementation".
© 2010 - cnpmjs.org x YWFE | Home | YWFE