Wednesday, October 13, 2010

JavaScript: passing undefined number of arguments to a function

This is just for my own reference. Most of the time, I forget things that I have discovered. To keep track of everything, I decided to blog it instead, which is not a bad idea, right?

The question is how I can pass an undefined number of arguments to a function in Javascript. After googling for hours, I've finally gathered some enough information and have done some tests. Here are the 4 huge lines of efforts. :P

function eatanything(args)
{
alert(arguments.length);
}
eatanything('hello','to','myself');
Google has all the answers you are seeking for. It is just a matter of giving a spot on keyword(s) to get the perfect answer. Yahoo! Answer is also a good option.

No comments:

Post a Comment