function deepClone(source){
if(typeof source == ('string'|| 'number')){
return source;
}
if(!source || typeof source != 'object'){
throw new Error("error arguments!")
}
var newSource = source.constructor === Array? [] : {};
for(var key in source){
if(source.hasOwnProperty(key)){
if(typeof source[key] !== 'object'){
newSource[key] = source[key]
}else{
newSource[key] = deepClone(source[key])
}
}
}
return newSource;
}
网友评论