Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork22
ES6 spec-compliant Object.assign shim. Fromhttps://github.com/es-shims/es6-shim
License
ljharb/object.assign
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
An Object.assign shim. Invoke its "shim" method to shim Object.assign if it is unavailable.
This package implements thees-shim API interface. It works in an ES3-supported environment and complies with thespec. In an ES6 environment, it will also work properly withSymbol
s.
Takes a minimum of 2 arguments:target
andsource
.Takes a variable sized list of source arguments - at least 1, as many as you want.Throws a TypeError if thetarget
argument isnull
orundefined
.
Most common usage:
varassign=require('object.assign').getPolyfill();// returns native method if compliant/* or */varassign=require('object.assign/polyfill')();// returns native method if compliant
varassert=require('assert');// Multiple sources!vartarget={a:true};varsource1={b:true};varsource2={c:true};varsourceN={n:true};varexpected={a:true,b:true,c:true,n:true};assign(target,source1,source2,sourceN);assert.deepEqual(target,expected);// AWESOME!
vartarget={a:true,b:true,c:true};varsource1={c:false,d:false};varsourceN={e:false};varassigned=assign(target,source1,sourceN);assert.equal(target,assigned);// returns the target objectassert.deepEqual(assigned,{a:true,b:true,c:false,d:false,e:false});
/* when Object.assign is not present */deleteObject.assign;varshimmedAssign=require('object.assign').shim();/* or */varshimmedAssign=require('object.assign/shim')();assert.equal(shimmedAssign,assign);vartarget={a:true,b:true,c:true};varsource={c:false,d:false,e:false};varassigned=assign(target,source);assert.deepEqual(Object.assign(target,source),assign(target,source));
/* when Object.assign is present */varshimmedAssign=require('object.assign').shim();assert.equal(shimmedAssign,Object.assign);vartarget={a:true,b:true,c:true};varsource={c:false,d:false,e:false};assert.deepEqual(Object.assign(target,source),assign(target,source));
Simply clone the repo,npm install
, and runnpm test
About
ES6 spec-compliant Object.assign shim. Fromhttps://github.com/es-shims/es6-shim
Resources
License
Code of conduct
Security policy
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Sponsor this project
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Contributors6
Uh oh!
There was an error while loading.Please reload this page.