Today, I wrote a small program with JavaScript. There is a small discovery when I use the array, and I have not introduced the books of the hand, so I will send it.
First we define an array and give it a value, then define an empty array, an empty array = Country group:
/ **************** code segment one ****************
Var Array1 = New Array ("A", "B", "C");
Var array2 = new array ();
Array2 = array1;
/ *************************************************
My purpose is to use the new array to temporarily store the original array data, because I may change the data of these data, but I don't want to change the original array, so I use a new temporary array to store this data. But the result of run is that I operate the new array, the value of the original number changes.
/ **************** Code segment two *****************
Array2.pop ();
Array2.push ("d");
VAR Tempstr = ""
For (VAR i = 0; i <= array1.length; i )
Tempstr = array1 [i];
Alert (Tempstr);
/ *************************************************
This reminds me of C / C references or pointers, but I have passed the various JavaScript manuals or tutorials that I have passed over the hand, but this new array is indeed a reference. This new array does not appear in this new array in other ways:
/ *************** Code section three *****************
Var Array1 = New Array ("A", "B", "C");
Var array2 = new array (array1);
/ *************************************************
Some think about: WIN's array object should be a Class written by VC , and the author does not overload "=", so the JavaScript array is directly used to assign a reference to the source array.