- Object.assign(target, source1, source2)
- 该方法用于对象的合并,将源对象(source)的所有可枚举属性,复制到目标对象。source1,source2可选,如果只有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}
如果只有一个参数,Object.assign()会直接返回该参数