Tuesday, September 13, 2011

Variable length arguments for javascript method

When creating javascrip method, if the parameters passed by caller may be different by any reason, an easy solution is just defining the parameters to empty, then inside the javascript method, accessing the actual parameter from the implicit argument variable.
The arguments variable inside the called function is an array containing the values of all the arguments passed to the function by caller, as shown in the following example:
function test()
{
alert(arguments[1]);
}

test("0","1","2");

John

No comments:

Post a Comment