globalthis (1.0.4)
Published 2026-02-24 13:57:23 +00:00 by atheaadmin
Installation
registry=npm install globalthis@1.0.4"globalthis": "1.0.4"About this package
globalThis 
An ECMAScript spec-compliant polyfill/shim for globalThis. Invoke its "shim" method to shim globalThis if it is unavailable.
This package implements the es-shim API interface. It works in an ES3-supported environment and complies with the spec proposal.
Most common usage:
var globalThis = require('globalthis')(); // returns native globalThis if compliant
/* or */
var globalThis = require('globalthis/polyfill')(); // returns native globalThis if compliant
Example
var assert = require('assert');
// the below function is not CSP-compliant, but reliably gets the
// global object in sloppy mode in every engine.
var getGlobal = Function('return this');
assert.equal(globalThis, getGlobal());
/* when `globalThis` is not present */
var shimmedGlobal = require('globalthis').shim();
/* or */
var shimmedGlobal = require('globalthis/shim')();
assert.equal(shimmedGlobal, globalThis);
assert.equal(shimmedGlobal, getGlobal());
/* when `globalThis` is present */
var shimmedGlobal = require('globalthis').shim();
assert.equal(shimmedGlobal, globalThis);
assert.equal(shimmedGlobal, getGlobal());
Tests
Simply clone the repo, npm install, and run npm test
Dependencies
Dependencies
| ID | Version |
|---|---|
| define-properties | ^1.2.1 |
| gopd | ^1.0.1 |
Development Dependencies
| ID | Version |
|---|---|
| @es-shims/api | ^2.5.0 |
| @ljharb/eslint-config | ^21.1.0 |
| aud | ^2.0.4 |
| auto-changelog | ^2.4.0 |
| browserify | ^16.5.2 |
| eslint | =8.8.0 |
| for-each | ^0.3.3 |
| in-publish | ^2.0.1 |
| is | ^3.3.0 |
| npmignore | ^0.3.1 |
| nyc | ^10.3.2 |
| safe-publish-latest | ^2.0.0 |
| tape | ^5.7.5 |
Keywords
window
self
global
globalThis
System.global
global object
global this value
ECMAScript
es-shim API
polyfill
shim
