如题,有个例子
export function deepCopy (obj, cache = []) {
if (obj === null || typeof obj !== 'object') {
return obj
}
const hit = cache.filter(c => c.original === obj)[0]
if (hit) {
return hit.copy
}
const copy = Array.isArray(obj) ? [] : {}
cache.push({
original: obj,
copy
})
Object.keys(obj).forEach(key => {
copy[key] = this.deepCopy(obj[key], cache)
})
return copy
}
但是我用这个就一直报错这个方法不存在
找不到模块,可能是路径不对。
但是deepCopy 函数里面
copy[key] = this.deepCopy(obj[key], cache)
为什么用
this.deepCopy
递归?