深复制

 var newObj = JSON.parse( JSON.stringify( someObj ) );

浅复制

var myObject = { 
a: 2,
b: anotherObject, // 引用,不是复本! 
c: anotherArray, // 另一个引用!
d: anotherFunction
};

var newObj = Object.assign( {}, myObject );
     newObj.a; // 2
     newObj.b === anotherObject; // true
     newObj.c === anotherArray; // true
     newObj.d === anotherFunction; // true

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-01
  • 2021-06-06
  • 2021-10-26
猜你喜欢
  • 2021-10-01
  • 2022-12-23
  • 2022-02-13
  • 2021-11-28
  • 2022-12-23
  • 2021-06-20
  • 2022-12-23
相关资源
相似解决方案