globalThis

ECMAScript spec-compliant polyfill/shim for `globalThis`.

  • 所有者: es-shims/globalThis
  • 平台:
  • 許可證: MIT License
  • 分類:
  • 主題:
  • 喜歡:
    0
      比較:

Github星跟蹤圖

globalThis Version Badge

Build Status
dependency status
dev dependency status
License
Downloads

npm badge

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

主要指標

概覽
名稱與所有者es-shims/globalThis
主編程語言JavaScript
編程語言JavaScript (語言數: 1)
平台
許可證MIT License
所有者活动
創建於2016-03-30 05:02:19
推送於2024-04-30 02:35:55
最后一次提交
發布數7
最新版本名稱v1.0.4 (發布於 2024-04-29 19:35:49)
第一版名稱system.global-v1.0.0 (發布於 )
用户参与
星數156
關注者數6
派生數13
提交數82
已啟用問題?
問題數9
打開的問題數2
拉請求數8
打開的拉請求數0
關閉的拉請求數2
项目设置
已啟用Wiki?
已存檔?
是復刻?
已鎖定?
是鏡像?
是私有?