Object#assign
assign(target, source)
把源对象复制到目标对象,如果有相同属性,source会覆盖掉target中的,可以有多个源对象,后面的source会覆盖前面的source的相同属性;
浅拷贝,如果属性中有对象,则复制的是对象的引用,target修改时也会影响到source;
示例
var o1 = {"a": 1, "b": 2, "c": {"c1": 3, "c2": 4}};
var o2 = {"a": 11};
var o3 = {"b": 111};
o2.c.c1 = 5;
Object.assign(o2, o1, o3);
console.log(JSON.stringify(o1));
console.log(JSON.stringify(o2));
// {"a":1,"b":2,"c":{"c1":5,"c2":4}}
// {"a":1,"b":111,"c":{"c1":5,"c2":4}}
目标o2.a被o1.a覆盖了;
o1.b被o3.b覆盖了;
改变o2.c.c后o1.c.c1也被改变了;