I am not sure how many of you believed that if we declare a function like this
function SumAll(){}
then you cannot pass any argument to it (I believed it .. till few days back). On the contrary to the general belief these functions are known as variable argument functions and can accept any number of arguments that are passed to them, which means we call this function in any of the ways mentioned below.
SumAll(1,3,5,6,7,8);
SumAll();
SumAll(4,7,8);
Now, you may ask me a question, what good a function is if I don’t know what is going to be passed it and how do I process these arguments. The answer to this question is arguments property (
confused). Ok, Ok let’s not waste your precious time anymore.
Siebel implicitly passes an argument property which is an array called “arguments” to these functions. The first variable passed to a function is referred to as arguments[0], the second as arguments[1], and so forth.
This property allows us to have a function with indefinite number of arguments. Here is a sample function to explain the working of this property.
function SumAll()
{
var total = 0;
for (var i = 0; i < arguments.length; i++)
{
total += arguments[i];
}
return total;
}
The above mentioned function will return total of all the arguments supplied to it.
You can also pass complex object types such as Property Set, Arrays etc as these are passed by reference to the functions. Now, use your imagination to make use of this property.
P.S: I am trying to use this property to lay foundation of an Error Handling Framework


(2 votes, average: 4.50 out of 5)