js Object reference bug All In One
js Object reference bug All In One
arr1 = [1,2,3];
(3) [1, 2, 3]
arr2 = arr1;
(3) [1, 2, 3]
arr2.push(4);
4
arr1;
(4) [1, 2, 3, 4]
arr2;
(4) [1, 2, 3, 4]
arr1 = [1,2,3];
(3) [1, 2, 3]
// 解构赋值
arr2 = [...arr1];
(4) [1, 2, 3]
arr2.push(4);
4
arr1;
(4) [1, 2, 3]
arr2;
(4) [1, 2, 3, 4]
deep clone & deep copy
refs
©xgqfrms 2012-2020
www.cnblogs.com 发布文章使用:只允许注册用户才可以访问!
原创文章,版权所有©️xgqfrms, 禁止转载 🈲️,侵权必究⚠️!
本文首发于博客园,作者:xgqfrms,原文链接:https://www.cnblogs.com/xgqfrms/p/14690886.html
未经授权禁止转载,违者必究!