Array
Today, using JavaScript to write a small program, using an array of a small discovery, turned the book at hand did not introduce, so sent over shortcoming.
First we define an array and assign it a value, and then define an empty array, another empty array = the original array:
/***************** Code Snippet a *****************
var array1 = new Array ("A", "B", "C");
var array2 = new Array ();
Array2 = Array1;
/******************************************
My intention was to use the new array to temporarily store the original array data, because I could change the data, but I didn't want to change the original array, so I used a new temporary array to store the data. But the result of the operation was that I manipulated the new array, and the value of the original number also changed.
/***************** Code Snippet two *****************
Array2.pop ();
Array2.push ("D");
var tempstr = "";
for (var i=0; i<=array1.length; i++)
TempStr + = Array1[i];
alert (TEMPSTR);
/******************************************
It reminded me of the references or pointers in C/s + +, but I did not mention the concept by rummaging through the various JavaScript manuals or tutorials at hand, but the new array is indeed a reference to the original array. The other way to initialize the new array does not occur:
/**************** Code Snippet three ******************
var array1 = new Array ("A", "B", "C");
var array2 = new Array (array1);
/******************************************
Some think: Win under the JavaScript of the array object should be VC + + write class, and the author does not overload "=", so that the JavaScript array directly with "=" assignment to become a reference to the source array.