xgqfrms™, xgqfrms® : xgqfrms's offical website of cnblogs! xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!

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, 禁止转载 🈲️,侵权必究⚠️!


posted @ 2021-04-22 18:11  xgqfrms  阅读(59)  评论(3编辑  收藏  举报