ES6-Object.assign()

Object.assign方法用于对象的合并,将源对象(source)的所有可枚举属性,复制到目标对象(target)。

const target = { a: 1, b: 1 };

const source1 = { b: 2, c: 2 };
const source2 = { c: 3 };

Object.assign(target, source1, source2);
target // {a:1, b:2, c:3}

参考文档:https://www.jianshu.com/p/d5f572dd3776

猜你喜欢

转载自www.cnblogs.com/XUYIYUAN/p/12662075.html