深拷贝方法
function deepClone(source) {
if (source === null || typeof source !== 'object')
return source;
const target = source.constructor === Array ? [] : {}
for (let key in source) {
// 忽略从原型链上继承的属性
if (source.hasOwnProperty(key)) {
if (source[key] && typeof source[key] === 'object')
target[key] = deepClone(source[key])
else
target[key] = source[key]
}
}
return target
}
本文来自博客园,作者:Bin_x,转载请注明原文链接:https://www.cnblogs.com/Bin-x/p/15978978.html