0.0.3 • Published 5 years ago

obj-assign v0.0.3

Weekly downloads
5
License
MIT
Repository
github
Last release
5 years ago

obj-assign

Object.assign copies all own enumerable values but does not copies getters, setters and other value descriptors. This library allows you copy with all property descriptors of object.

npm.io Build Status PRs Welcome GitHub

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign#Description The Object.assign() method only copies enumerable and own properties from a source object to a target object. It uses [Get] on the source and [Set] on the target, so it will invoke getters and setters. Therefore it assigns properties versus just copying or defining new properties. This may make it unsuitable for merging new properties into a prototype if the merge sources contain getters.

Installation

npm install obj-assign

or

yarn add obj-assign

Usage

const assign = require('obj-assign');

const obj = Object.create({}, {
  bar: {
    enumerable: true,
    value: 'bar',
  },
  foo: {
    enumerable: true,
    get: function() {
      return this.bar;
    }
  }
});

const clone = assign({}, obj);

clone.bar = 'Hello World';

clone.foo // 'Hello World'

License

MIT

0.0.3

5 years ago

0.0.2

5 years ago

0.0.1

5 years ago