該對(duì)象代表正在執(zhí)行的函數(shù)和調(diào)用它的函數(shù)的參數(shù)。
[function.]arguments[n]
不能顯式創(chuàng)建 arguments 對(duì)象。arguments 對(duì)象只有函數(shù)開始時(shí)才可用。函數(shù)的 arguments 對(duì)象并不是一個(gè)數(shù)組,訪問單個(gè)參數(shù)的方式與訪問數(shù)組元素的方式相同。索引 n 實(shí)際上是 arguments 對(duì)象的 0…n 屬性的其中一個(gè)參數(shù)。
下面的示例演示了 arguments 對(duì)象的用法。
function ArgTest(a, b){
var i, s = "The ArgTest function expected ";
var numargs = arguments.length; // 獲取被傳遞參數(shù)的數(shù)值。
var expargs = ArgTest.length; // 獲取期望參數(shù)的數(shù)值。
if (expargs < 2)
s += expargs + " argument. ";
else
s += expargs + " arguments. ";
if (numargs < 2)
s += numargs + " was passed.";
else
s += numargs + " were passed.";
s += "\n\n"
for (i =0 ; i < numargs; i++){ // 獲取參數(shù)內(nèi)容。
s += " Arg " + i + " = " + arguments[i] + "\n";
}
return(s); // 返回參數(shù)列表。
}