globalthis
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|---|---|---|---|---|
define-properties | 1.2.1 | 5.08 kB | MIT | prod |
The globalThis
is an ECMAScript spec-compliant polyfill/shim package. It aims to provide a reliable and consistent reference to the global object, which is globalThis
in JavaScript, across all different environments. The globalThis
achieves this by providing a shim method. This method allows globalThis
, if unavailable, to be shimmed or replaced.
To use globalThis
, you will need to require the package in your project. Here are some examples of how to use it in your code:
// Returns native globalThis if compliant
var globalThis = require('globalthis')();
// Alternatively, you can also use the polyfill
var globalThis = require('globalthis/polyfill')();
/*
When `globalThis` is not present, you can use the shim method
This ensures that `globalThis` is available across all environments
*/
var shimmedGlobal = require('globalthis').shim();
// And using the shim from a different path
var shimmedGlobal = require('globalthis/shim')();
Remember, these lines of code return a reference to the global this
object, ensuring that globalThis
is available in your code, no matter what environment you're running it in.
The globalThis
package documents are available on Github. You can access more detailed documentation and usage examples by visiting the repository's readme file at this address: git://github.com/ljharb/System.global.git. From here, you can learn more about the package, including its implementation of the es-shim API interface, its usage in an ES3-supported environment, and its compliance with the spec proposal. The readme also provides various usage examples for the globalThis
package, as well as its tests. Regularly visiting this address will keep you updated on any changes or updates to the globalThis
package.