Object.assign()
Syntax: Object.assing (target, ... sources)
A combined target
const first = { name: "Bob" }; const last = { lastName: "Smith" }; let person = Object.assign(first, last); console.log(person);/*{ name: 'Bob', lastName: 'Smith' }*/
II clone
const obj = { person: "Bob Smith"}; const clone = Object.assign({}, obj); console.log(obj);/*{ person: 'Bob Smith' }*/
Three, " null or undefined source is considered null object treated the same, will not have any impact on the target audience."
const test = null; const test1 = Object.assign({},test); console.log(test1);/*{}*/
undefined test2 = const; const test4 = Object.assign ({}, test2); the console.log (test4); / * {} * /
can be seen from the above, test1 and test4 still empty object
Reproduced in: https: //www.cnblogs.com/yangxuan/p/11076199.html