标签:
var srcObj = {
a: 1,
b: {
b1: ["hello", "hi"],
b2: "JavaScript"
}
};
console.log(srcObj);
var clone1 = cloneObject(srcObj);
function cloneObject(src) {
var clone = {};
for(var item in src){
if(typeof(src[item])==‘object‘ ){
if(src[item] instanceof Array){
clone[item] = [];
for(var i=0,len=src[item].length; i<len; i++){
clone[item][i] = src[item][i];
}
} else {
clone[item] = cloneObject(src[item]);
}
} else{
clone[item] = src[item];
}
}
return clone;
}
console.log(clone1);
深度克隆(对象、数组)--------百度IFE前端task2
标签:
原文地址:http://www.cnblogs.com/dxiaoer/p/5103025.html