ES6 Object.assign()

Object.assign () method is used to enumerate all the attribute values ​​are copied from one or more source object to the target object. It will return to the target object.

grammar:

Object.assign(target, ...sources)

:( parameter is to copy the sources of the things to target where to save up)

If the same name attribute, between the front cover behind the target object and the source object.

target target.
sources Source object (which may be several)

return value:

target.

Copy an object

const obj = { a: 1 };
const copy = Object.assign({}, obj);
console.log(copy); // { a: 1 }

Guess you like

Origin www.cnblogs.com/XiaoYEBLog/p/11387660.html