为什么在JavaScript中更改Array会影响数组的副本?
var myArray = ['a', 'b', 'c'];var copyOfMyArray = myArray;copyOfMyArray.splice(0, 1);alert(myArray); // alerts ['b','c']alert(copyOfMyArray); // alerts ['b','c']var myNumber = 5;var copyOfMyNumber = myNumber;copyOfMyNumber = copyOfMyNumber - 1;alert(myNumber); // alerts 5alert(copyOfMyNumber); // alerts 4
myArray
copyOfMyArray
myArray
copyOfMyArray
myArray
copyOfMyArray
copyOfMyArray
myArray
.
myNumber
copyOfMyNumber
myNumber
copyOfMyNumber
myNumber
copyOfMyNumber
myNumber
copyOfMyNumber
.
三国纷争
茅侃侃
万千封印
相关分类