function deepCopy(obj){
//判斷是否是簡單數(shù)據(jù)類型,
if(typeof obj == "object"){
//復(fù)雜數(shù)據(jù)類型
var result = obj.constructor == Array ? [] : {};
for(let i in obj){
result[i] = typeof obj[i] == "object" ? deepCopy(obj[i]) : obj[i];
}
}else {
//簡單數(shù)據(jù)類型 直接 == 賦值
var result = obj;
}
return result;
}
乞丐版
var newObj = JSON.parse( JSON.stringify( someObj ) );