📜  在 javascript 代码示例中克隆对象的最佳方法

📅  最后修改于: 2022-03-11 15:03:49.333000             🧑  作者: Mango

代码示例5
const person = {
    firstName: 'John',
    lastName: 'Doe'
};


// using spread ...
let p1 = {
    ...person
};

// using  Object.assign() method
let p2 = Object.assign({}, person);

// using JSON
let p3 = JSON.parse(JSON.stringify(person));