object.assign
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|---|---|---|---|---|
define-properties | 1.2.1 | 5.08 kB | MIT | prod | |
function-bind | 1.1.2 | 9.57 kB | MIT | prod | |
has-symbols | 1.0.3 | 6.9 kB | MIT | prod | |
object-keys | 1.1.1 | 7.5 kB | MIT | prod |
Object.assign is an ES6 spec-compliant npm package that provides a 'shim' for the Object.assign method in JavaScript. A shim is a library that brings new API to an older environment. Thus, if the Object.assign method is unavailable, invoking object.assign's "shim" method can provide the functionality. The package implements the es-shim API interface and works in an ES3-supported environment and also in an ES6 environment with Symbol.
Using object.assign in your code is simple and straightforward. It's included into your project via the require function. You can obtain the polyfill using either one of the following lines of code in Node.js
var assign = require('object.assign').getPolyfill();
var assign = require('object.assign/polyfill')();
You can then apply 'assign' onto your target object with one or multiple source objects:
var target = { a: true };
var source1 = { b: true };
var source2 = { c: true };
var sourceN = { n: true };
assign(target, source1, source2, sourceN);
Upon execution, 'target' will have attributes of all the source objects. In case of attribute conflicts, the value from the latest source object will be kept.
The documentation for object.assign can be found within its README file at the GitHub repository object.assign. This includes detailed usage examples and function behaviors for various scenarios.