看完下面的**,相信對js物件引用又有了新的認識,直接上**:
1//split()把字串分割成字串陣列2//
reverse() 會改變陣列本身,**並返回原陣列的引用**。!!!!
3var arr1 = "john".split(''); //
arr1=["j","o","h","n"]45
var arr2 = arr1.reverse(); //
arr1 = arr2 = ["n","h","o","j"]; arr1 and arr2有相同的引用67
var arr3 = "jones".split(''); //
arr3=["j","o","n","e","s"];
89 arr2.push(arr3); //
arr2=["n","h","o","j",["j","o","n","e","s"]]
10//
arr1 and arr2有相同的引用 so: arr1=["n","h","o","j",["j","o","n","e","s"]]
1112 console.log("array 1: length=" + arr1.length + " last=" + arr1.slice(-1));
13//
array 1: length=5 last=j,o,n,e,s
1415 console.log("array 2: length=" + arr2.length + " last=" + arr2.slice(-1));
16//
array 2: length=5 last=j,o,n,e,s
1718
19var myarr = [1,2,3,4];
20var myarr2 = [5,6,7,8];
21 console.log(myarr.slice(-1)); //
[4]22
myarr.push(myarr2);
23 console.log(myarr); //
[1, 2, 3, 4, array[4]]
關於 引用 的簡單例子
一般而言,引用的使用限制在以下三種情況 1.引數本身必須改變 2.要傳回兩個以上的值 3.有大量引數需要傳遞,如果不使用引用,則將耗費時間在引數的複製上.例如引數為大型向量或矩陣的情況.以下是簡單的引用的例子 temp2.cpp 定義控制台應用程式的入口點。include stdafx.h incl...
JS的for迴圈小例子
1 輸出1 100的和 var sum 0 for var i 1 i 100 i document.write sum 2 輸出1 100奇數的和 var sum 0 for var i 1 i 100 i 2 document.write sum 3 輸出1 100偶數的和 var sum 0 ...
幾個js的小例子
1 js的作用域,window物件 if a in window alert a 1 js的作用域是由函式劃分的 2 js的執行順序 var a 1,b function a x alert a 1 3 js引數 arguments 的含義 function b x,y,a b 1,2,3 10 4...