peach a19a732be8 commit message | 2 vuotta sitten | |
---|---|---|
.. | ||
test | 2 vuotta sitten | |
.editorconfig | 2 vuotta sitten | |
.eslintignore | 2 vuotta sitten | |
.eslintrc | 2 vuotta sitten | |
.nycrc | 2 vuotta sitten | |
CHANGELOG.md | 2 vuotta sitten | |
LICENSE | 2 vuotta sitten | |
README.md | 2 vuotta sitten | |
auto.js | 2 vuotta sitten | |
implementation.js | 2 vuotta sitten | |
index.js | 2 vuotta sitten | |
package.json | 2 vuotta sitten | |
polyfill.js | 2 vuotta sitten | |
shim.js | 2 vuotta sitten |
An ES2017 spec-compliant shim for Object.getOwnPropertyDescriptors
that works in ES5.
Invoke its "shim" method to shim Object.getOwnPropertyDescriptors
if it is unavailable, and if Object.getOwnPropertyDescriptor
is available.
This package implements the es-shim API interface. It works in an ES3-supported environment and complies with the spec.
var getDescriptors = require('object.getownpropertydescriptors');
var assert = require('assert');
var obj = { normal: Infinity };
var enumDescriptor = {
enumerable: false,
writable: false,
configurable: true,
value: true
};
var writableDescriptor = {
enumerable: true,
writable: true,
configurable: true,
value: 42
};
var symbol = Symbol();
var symDescriptor = {
enumerable: true,
writable: true,
configurable: false,
value: [symbol]
};
Object.defineProperty(obj, 'enumerable', enumDescriptor);
Object.defineProperty(obj, 'writable', writableDescriptor);
Object.defineProperty(obj, 'symbol', symDescriptor);
var descriptors = getDescriptors(obj);
assert.deepEqual(descriptors, {
normal: {
enumerable: true,
writable: true,
configurable: true,
value: Infinity
},
enumerable: enumDescriptor,
writable: writableDescriptor,
symbol: symDescriptor
});
var getDescriptors = require('object.getownpropertydescriptors');
var assert = require('assert');
/* when Object.getOwnPropertyDescriptors is not present */
delete Object.getOwnPropertyDescriptors;
var shimmedDescriptors = getDescriptors.shim();
assert.equal(shimmedDescriptors, getDescriptors);
assert.deepEqual(shimmedDescriptors(obj), getDescriptors(obj));
var getDescriptors = require('object.getownpropertydescriptors');
var assert = require('assert');
/* when Object.getOwnPropertyDescriptors is present */
var shimmedDescriptors = getDescriptors.shim();
assert.notEqual(shimmedDescriptors, getDescriptors);
assert.deepEqual(shimmedDescriptors(obj), getDescriptors(obj));
Simply clone the repo, npm install
, and run npm test