const checkTargetType = target => Object.prototype.toString.call(target).slice(8,-1);
const clone = target => {
let result,targetType = checkTargetType(target)
if(targetType === 'Object' || targetType === 'Array'){
result = targetType === 'Object'?{}:[]
}else{
return target;
}
for(let i in target){
result[i] = clone(target[i])
}
return result;
}
js 笔记 数据的深度克隆
猜你喜欢
转载自blog.csdn.net/AJINGJINGJJ/article/details/81156249
今日推荐
周排行