const deepClone = (target, cache = new Map()) => { const isObject = (obj) => typeof obj === 'object' && obj !== null if (isObject(target)) { // 解决循环引用 const cacheTarget = cache.get(target) // 已经存在直接返回,无需再次解析 if (cacheTarget) { return cacheTarget } let cloneTarget = Array.isArray(target) ? [] : {} cache.set(target, cloneTarget) for (const key in target) { if (target.hasOwnProperty(key)) { const value = target[ key ] cloneTarget[ key ] = isObject(value) ? deepClone(value, cache) : value } } return cloneTarget } else { return target }}const target = { field1: 1, field2: undefined, field3: { child: 'child' }, field4: [2, 4, 8], f: { f: { f: { f: { f: { f: { f: { f: { f: { f: { f: { f: {} } } } } } } } } } } },};target.target = target;const result1 = deepClone(target);console.log(result1)