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
原文地址:https://www.cnblogs.com/c-x-a/p/14266230.html