Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including define-properties with all npm packages installed. Try it out:

var defineProperties = require("define-properties")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

define-properties v1.1.3

Define multiple non-enumerable properties at once. Uses `Object.defineProperty` when available; falls back to standard assignment in older engines.

#define-properties Version Badge

Build Status dependency status dev dependency status License Downloads

npm badge

browser support

Define multiple non-enumerable properties at once. Uses Object.defineProperty when available; falls back to standard assignment in older engines. Existing properties are not overridden. Accepts a map of property names to a predicate that, when true, force-overrides.

Example

var define = require('define-properties');
var assert = require('assert');

var obj = define({ a: 1, b: 2 }, {
    a: 10,
    b: 20,
    c: 30
});
assert(obj.a === 1);
assert(obj.b === 2);
assert(obj.c === 30);
if (define.supportsDescriptors) {
    assert.deepEqual(Object.keys(obj), ['a', 'b']);
    assert.deepEqual(Object.getOwnPropertyDescriptor(obj, 'c'), {
        configurable: true,
        enumerable: false,
        value: 30,
        writable: false
    });
}

Then, with predicates:

var define = require('define-properties');
var assert = require('assert');

var obj = define({ a: 1, b: 2, c: 3 }, {
    a: 10,
    b: 20,
    c: 30
}, {
    a: function () { return false; },
    b: function () { return true; }
});
assert(obj.a === 1);
assert(obj.b === 20);
assert(obj.c === 3);
if (define.supportsDescriptors) {
    assert.deepEqual(Object.keys(obj), ['a', 'c']);
    assert.deepEqual(Object.getOwnPropertyDescriptor(obj, 'b'), {
        configurable: true,
        enumerable: false,
        value: 20,
        writable: false
    });
}

Tests

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

Metadata

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free