JS深拷贝

89 阅读1分钟

JavaScript中深拷贝的方法

// 1.使用JSON的方法
const obj1 = JSON.parse(JSON.stringfy(obj));
// 2.使用defineProperties
Object.defineProperties(obj1,Object.getOwnPropertyDescriptors(obj))
// 3.使用遍历拷贝