obj-assign

0.0.3 • Public • Published

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.

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

Package Sidebar

Install

npm i obj-assign

Weekly Downloads

8

Version

0.0.3

License

MIT

Unpacked Size

110 kB

Total Files

7

Last publish

Collaborators

  • doniyor2109