var a = [ { name: 'is_empty', items: ['1', '2', '3', '4', '5'] }, { name: 'is_true', items: ['6', '7', '8', '9', '10'] }]var b = []for (var i = 0; i < a.length; i++) { b[i] = a[i]}// 注释掉a[0] = [], 此时B 为{[], ['1', '2', '3', '4', '5']}// 未注释掉的情况下,B为{[1, 2, 3, 4, 5]}, {[6, 7, 8, 9, 10]}// a[0] = []// console.log(b) // {['6', '7', '8', '9', '10']}, {['6', '7', '8', '9', '10']}// a[0].items = []// console.log(b) // {[], [6, 7, 8, 9, 10]}重置a[0] = []的时候,数组的引用被切断了,但是如果只重置a[0].items = []时候,引用却并未被切断,这是为什么?
添加回答
举报
0/150
提交
取消