[function.]arguments.length

      notes 2005-6-3 11:10
function argTest(a, b) : String {
var i : int;
var s : String = "The argTest function expected ";
var numargs : int = arguments.length; // Get number of arguments passed.
var expargs : int = argTest.length; // Get number of arguments expected.
if (expargs < 2)
s += expargs + " argument. ";
else
s += expargs + " arguments. ";
if (numargs < 2)
s += numargs + " was passed.";
else
s += numargs + " were passed.";
s += "\n"
for (i =0 ; i < numargs; i++){ // Get argument contents.
s += " Arg " + i + " = " + arguments[i] + "\n";
}
return(s); // Return list of arguments.
}

print(argTest(42));
print(argTest(new Date(1999,8,7),"Sam",Math.PI));
当使用 /fast- 选项编译后,该程序的输出为:

The argTest function expected 2 arguments. 1 was passed.
Arg 0 = 42

The argTest function expected 2 arguments. 3 were passed.
Arg 0 = Tue Sep 7 00:00:00 PDT 1999
Arg 1 = Sam
Arg 2 = 3.141592653589793
标签集:TAGS:
回复Comments() 点击Count()

回复Comments

{commentauthor}
{commentauthor}
{commenttime}
{commentnum}
{commentcontent}
作者:
{commentrecontent}