对象合并方式## 标题
1、Object.assign() 方法
let a = {a:1,b:2}
let b = {c:3,d:4}
let newObj = Object.assign(a,b) //{a:1,b:2,c:3,d:4}
2、使用es6扩展运算符
let a = {a:1,b:2}
let b = {c:3,d:4}
let newObj = {...a,...b} //{a:1,b:2,c:3,d:4}
3、封装方法 使用for in
function extend(target,source){
for(let key in source){
target[key] = source[key]
}
return target
}
extend(a,b)