Closed playjump closed 2 years ago
function deepClone(src) { if (typeof src !== "object") { return src; } function clone(src, target) { const cplist = []; for (const key in src) { if (typeof src[key] === "object") { target[key] = new src[key].constructor(); cplist.push([src[key], target[key]]); } else { target[key] = src[key]; } } return cplist; } const result = new src.constructor(); let cplist = clone(src, result); while (cplist.length) { let newList = []; for (const value of cplist) { newList = newList.concat(clone(value[0], value[1])); } cplist = newList; } return result; }