//arguments 对象的用法。 function ArgTest(a, b){ var i, s = "The ArgTest function expected "; var numargs = arguments.length; // 获取被传递参数的数值。 var expargs = ArgTest.length; // 获取期望参数的数值。 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++){ // 获取参数内容。 s += " Arg " + i + " = " + arguments[i] + "\n"; } return(s); // 返回参数列表。 }
在此添加了一个说明arguments不是数组(Array类)的代码:
Array.prototype.selfvalue = 1; alert(new Array().selfvalue); function testAguments(){ alert(arguments.selfvalue); }
// caller demo { function callerDemo() { if (callerDemo.caller) { var a= callerDemo.caller.toString(); alert(a); } else { alert("this is a top function"); } } function handleCaller() { callerDemo(); }
callee
返回正被执行的 Function 对象,也就是所指定的 Function 对象的正文。
[function.]arguments.callee 可选项 function 参数是当前正在执行的 Function 对象的名称。