1 function deepClone(origin,target){ 2 var target = target || {}, 3 toStr = Object.prototype.toString, 4 arrStr = "[object Array]"; 5 for(var prop in origin){ 6 if(origin.hasOwnProperty(prop)){ 7 if (origin[prop] !== "null" && typeof(origin[prop]) == "object") { 8 if (toStr.call(origin[prop]) == arrStr) { 9 target[prop] = []; 10 }else{ 11 target[prop] = {}; 12 } 13 deepClone(origin[prop],target[prop]); 14 }else{ 15 target[prop] = origin[prop] 16 } 17 18 } 19 } 20 return target; 21 } 22 23 24 var obj1 = { 25 name:'zhang', 26 age:25, 27 hobit:{ 28 sport:["basketball","football","run"], 29 learn:{ 30 name:"xxxx", 31 catgory:["123",456] 32 } 33 } 34 } 35 36 37 var obj = {}; 38 39 deepClone(obj1,obj)