js 深拷貝函數(shù)
更新時間:2008年12月04日 01:05:00 作者:
Javascript中的對像賦值與Java中是一樣的,都為引用傳遞.就是說,在把一個對像賦值給一個變量時,那么這個變量所指向的仍就是原來對像的地址.那怎么來做呢 答案是克隆.
function objectClone(obj,preventName){
if((typeof obj)=='object'){
var res=(!obj.sort)?{}:[];
for(var i in obj){
if(i!=preventName)
res[i]=objectClone(obj[i],preventName);
}
return res;
}else if((typeof obj)=='function'){
return (new obj()).constructor;
}
return obj;
}
if((typeof obj)=='object'){
var res=(!obj.sort)?{}:[];
for(var i in obj){
if(i!=preventName)
res[i]=objectClone(obj[i],preventName);
}
return res;
}else if((typeof obj)=='function'){
return (new obj()).constructor;
}
return obj;
}
相關文章
javascript中動態(tài)函數(shù)用法實例分析
這篇文章主要介紹了javascript中動態(tài)函數(shù)用法,實例分析了動態(tài)函數(shù)的定義方法與使用技巧,需要的朋友可以參考下2015-05-05