JS对象深拷贝
// 对象深拷贝(数组和对象)
function deepClone(resource) {
if (Array.isArray(resource)) {
let dest = []
let length = resource.length
while (length--) {
console.log(length)
dest[length] = deepClone(resource[length])
}
return dest
} else if (typeof resource === 'object') {
let dest = {}
for (let key in resource) {
if (resource.hasOwnProperty(key)) {
dest[key] = deepClone(resource[key])
}
}
return dest
}
return resource
}