Ecma6, Object.assign doesn't do a deep copy
This question already has an answer here:
First I want to tell you that it's not bulletproof solution(in case of date object). If you want "right" as answer,here is your solution `
var dst,src = { "edf" : {"zyx" : "right"}};
dst=JSON.parse(JSON.stringify(src));
dst["a"] = 1;
src.edf.zyx = "wrong";
console.log(src,dst);
` So please read these links to understand deep copy better
Most elegant way to clone a JavaScript object
Copy JavaScript object to new variable NOT by reference?
链接地址: http://www.djcxy.com/p/24772.html上一篇: 克隆JSON不按预期工作