js中的复制

深复制

 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
posted @ 2021-01-12 11:46  公众号python学习开发  阅读(102)  评论(0编辑  收藏  举报