Object.assign方法用于对象的合并,将源对象(source)的所有可枚举属性,复制到目标对象(target)
const targetObj = { a1: 1 };
const sourceObj1 = { a2: 2 };
const sourceObj2 = { a3: 3 };
Object.assign(targetObj, sourceObj1, sourceObj2);
target // {a1:1, a2:2, a3:3}
const targetObj = { a1: 1 };
const sourceObj1 = { a2: 2 };
const sourceObj2 = { a3: 3 };
Object.assign(targetObj, sourceObj1, sourceObj2);
target // {a1:1, a2:2, a3:3}