function deepClone(obj, cache = new WeakMap()) {if (typeof obj !== 'object') return obj if (obj === null) return objif (cache.get(obj)) return cache.get(obj)if (obj instanceof Date) return new Date(obj)if (obj instanceof RegExp) return new RegExp(obj)if (typeof obj === 'symbol') return Symbol(obj.description) let cloneObj = new obj.constructor()cache.set(obj, cloneObj)for (let key in obj) {if (obj.hasOwnProperty(key)) {cloneObj[key] = deepClone(obj[key], cache)}}return cloneObj}const obj = { name: 'Jack', address: { x: 100, y: 200 }, a: [1, 2, 3, 4], b: Symbol('22') }obj.a = objconst newObj = deepClone(obj)console.log('obj', obj)console.log('newObj', newObj)