cloneTarget(target, map = new WeakMap()) { if (typeof target === 'object') { const isArray = Array.isArray(target); let cloneTarget = isArray ? [] : {}; if (map.get(target)) { return map.get(target); } map.set(target, cloneTarget); const keys = isArray ? undefined : Object.keys(target); this.forEach(keys || target, (value, key) => { if (keys) { key = value; } cloneTarget[key] = this.cloneTarget(target[key], map); }); return cloneTarget; } else { return target; } }, //深复制遍历方法用到 forEach(array, iteratee) { let index = -1; const length = array.length; while (++index < length) { iteratee(array[index], index); } return array; },