Re: Need code explanation
Just part of how Javascript works; you're not required to specify all (or any) of a function's arguments. If you write a function that's expected to have a consistent number of arguments, then it's good practice to (and simpler to work with if you) specify them. But if your function may accept a variable number of arguments, then you might use something like what you've got there; all functions have an "arguments" object by which you can access the passed arguments by numeric index.
It's not an approach you should use without good reason though.
Re: Need code explanation
Thanks SambaNeko, u've just saved me 3 days of wondering. Thank you soo much.
Re: Need code explanation
It's not necessary to qualify arguments:
Code:
Spry.Widget.Utils.firstValid = function() {
var ret = null;
for(var i=0; i<arguments.length; i++) {
if (typeof(arguments[i]) != 'undefined') {
ret = arguments[i];
break;
}
}
return ret;
};
Re: Need code explanation
another improvement:
Code:
Spry.Widget.Utils.firstValid = function() {
for (var i in arguments)
if (typeof arguments[i] !== 'undefined')
return arguments[i];
};
Not really sure of the value of this function, to be frank.