var oldArray = [],someArray=[],newArray=[];
oldArray = [4,5];
someArray =[1,2,3];
newArray = someArray;
for (var i=0; i<oldArray.length; i++){
someArray.push(oldArray[i]);
}
// I want this to be [1,2,3] but it becomes [1,2,3,4,5]
// due to scope issue I believe
oldArray = newArray;
在newArray
时,{p> someArray
必须是[1,2,3]
的原始oldArray = newArray
,但由于oldArray = newArray
[1,2,3,4,5]
成为someArray
代替。
我该如何解决这个问题?我需要保留原始oldArray
值并将这些值分配到addEventListener
。