UNPKG

vue-persistedstate

Version:

state management

24 lines 617 B
/* * @Author: zhang_gen_yuan * @Date: 2022-04-26 22:00:08 * @LastEditTime: 2022-04-26 22:00:09 * @Descripttion: */ export default function deepClone(obj, hash = new Map()) { if (typeof obj !== "object" && typeof obj !== null) { return obj; } let target = Array.isArray(obj) ? [] : {}; if (hash.has(obj)) return hash.get(obj); hash.set(obj, target); for (const key in obj) { if (Object.hasOwnProperty.call(obj, key)) { if (typeof obj[key] === "object") { target[key] = deepClone(obj[key], hash); } else { target[key] = obj[key]; } } } return target; }