1.“||”運算子 如果||運算子的第一個參數為true,或者是一個可以轉換為trued的值,該運算子就會返回其第一個參數。否則會返回第二個參數。例: a = a||[];如果a已經定義了並且為非null,它則返回a,否則a便是空的。
2.儘管定義javascript函數時有固定數目的具名引數,但當調用這個函數時,傳遞給它的參數數目卻可以是任意的。arguments對象允許完全地存取那些實際的參數值。arguments對象是一個類似數組的對象。
關於arguments的一個例子:
function b(a){
alert(a);
arguments[0]=[12,3];
alert(a);
}
b();//undefined,undefined
b(1);//"1","12,3";
-------------------------
從這個例子中可以看出來1.arguments對象是在有參數傳進來的時候才會初始劃分配記憶體的。2.arguments對象有一個非同尋常的特性,當函數具有命名了的參數時,arguments對象的數組元素是存放函數參數的局部變數的同義字。
3.callee屬性
arguments對象定義了callee屬性,用來引用當前正在執行的函數。這個屬性沒有多大的用處,但它可以用來允許對未命名的函數遞迴地進行調用 例
function(x){
if(x<=1) return 1;
return x*arguments.callee(x-1);
}
4.apply()方法和call()方法:apply()方法有兩個參數,用作this的對象和要傳遞個給函數的參數的數組。例如:
function sayColor(sPrefix,sSuffix) { alert(sPrefix + this.color + sSuffix);};var obj = new Object();obj.color = "blue";sayColor.call(obj, new Array("The color is ", "a very nice color indeed."));//最後產生的訊息仍是 "The color is blue, a very nice color indeed."
call()方法是與經典的對象冒充方法最相似的方法。它的第一個參數用作this的對象,其他參數直接傳遞給函數自身。
例:
function sayColor(sPrefix,sSuffix) { alert(sPrefix + this.color + sSuffix);};var obj = new Object();obj.color = "blue";sayColor.call(obj, "The color is ", "a very nice color indeed.");//最後產生的訊息 "The color is blue, a very nice color indeed."