function deepClone(origin){
if(!origin){
return '参数不能为空'
}
var toStr = Object.prototype.toString
var tar = toStr.call(origin) === '[object Object]' ? {} : []
for(var key in origin){
if(origin.hasOwnProperty(key)){
if(typeof(origin[key]) === 'object' && origin[key] !== null){
tar[key] = deepClone(origin[key])
}else{
tar[key] = origin[key]
}
}
}
return tar
}
js深拷贝
于 2022-10-25 16:42:57 首次发布