寫了一個純文字,感覺排版怪怪的,看下面的圖吧~就是一個標準的深複製,6不6就不知道了~~
function deepClone(origin,target) {
var target = target || {},
toStr = Object.prototype.toString,
arrStr = "[object Array]";
for(var prop in origin) {
if(origin.hasOwnProperty(prop)) {
if(origin[prop] !== "null" && typeof(origin[prop]) == "object"){
if(toStr.call(origin[prop]) == arrStr) {target[prop] = [];}
else{target[prop] = {}; }
deepClone(origin[prop],target[prop]);
}else{target[prop] = origin[prop]; }
}
return target;
寫了一個純文字,感覺排版怪怪的,看下面的圖吧~就是一個標準的深複製,6不6就不知道了~~
function deepClone(origin,target) {
var target = target || {},
toStr = Object.prototype.toString,
arrStr = "[object Array]";
for(var prop in origin) {
if(origin.hasOwnProperty(prop)) {
if(origin[prop] !== "null" && typeof(origin[prop]) == "object"){
if(toStr.call(origin[prop]) == arrStr) {target[prop] = [];}
else{target[prop] = {}; }
deepClone(origin[prop],target[prop]);
}else{target[prop] = origin[prop]; }
}
}
return target;
}