Home  >  Article  >  Web Front-end  >  js deep copy function

js deep copy function

高洛峰
高洛峰Original
2017-01-03 16:04:28985browse

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; 
}

For more js deep copy function related articles, please pay attention to the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn