2.0.0 • Published 8 years ago

system.global v2.0.0

Weekly downloads
15
License
MIT
Repository
github
Last release
8 years ago

#system.global Version Badge

Build Status dependency status dev dependency status License Downloads

npm badge

browser support

An ECMAScript spec-compliant polyfill/shim for global. Invoke its "shim" method to shim global 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 global = require('system.global')(); // returns native method if compliant
	/* or */
var global = require('system.global/polyfill')(); // returns native method 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(global, getGlobal());
/* when `global` is not present */
var shimmedGlobal = require('system.global').shim();
	/* or */
var shimmedGlobal = require('system.global/shim')();

assert.equal(shimmedGlobal, global);
assert.equal(shimmedGlobal, getGlobal());
/* when `global` is present */
var shimmedGlobal = require('system.global').shim();

assert.equal(shimmedGlobal, global);
assert.equal(shimmedGlobal, getGlobal());

Tests

Simply clone the repo, npm install, and run npm test