1、浅拷贝:
function shallowClone(obj){
let cloneObj = {}
for(let i in obj){
cloneObj[i] = obj[i]
}
return cloneObj
}
2、深拷贝:
function deepClone(obj){
var result
if(typeof obj === 'object'){
result = obj.constructor === Array?[]:{}
for(var i in obj){
result[i] = typeof obj[i] === 'object' ? deepClone(obj[i]):obj[i]
}
}else{
result = obj
}
return result
}