The mystery argument
Consider this:
window.setTimeout(foo,100,"bar","baz");
function foo(){
alert(arguments.length);
for (var arg = 0;arguments[arg];arg++){
alert(arg+": "+arguments[arg]);
}
}
What should the value of arguments.length be?
The documentation I use every day, suggest that you can pass any number of arguments in a window.setTimeout and have them available from the arguments array. However, that is not the case:
Internet Explorer
Internet Explorer won’t let me pass arguments to a setTimeout, and makes arguments.length == 0; — which is fair enough, The MSDN documentation suggests that only the optional lang parameter is allowed
Opera
Opera tells me that arguments.length == 2 which is exactly what I expected.
Mozilla/Firefox
And along comes the mystery: The Gecko DOM Reference states that no optional arguments are allowed. Supporting “language” doesn’t make much sense when you have only one scripting language.
However, in Gecko, arguments.length == 3 — where the first two values are arguments[0] == "bar"; and arguments[1] == "baz";. The last one, however is a mystery: It returns a numeric value. The value of arguments[2] is 10, 13 and 7, respectively.
Can anyone please enlighten me and tell me what this third value of the arguments array is, why it’s there and where it’s documented?
Comments
Comment from jaap on 2005-07-18 12:53
Could it be the timeOut ID? Try alerting the return value of the setTimeout call and compare it with arguments[2].
Comment from Arve on 2005-07-18 13:10
Nope, it is not the timeout ID. An example run reveals that the timeout ID is 3, while the value of the last argument is 76791834.
Comment from Lasse Marĝen on 2005-07-19 12:15
This might be something called timeout lateness (also read comments #5 and #7). Bugs 299476 and 243630 might also be of interest.
Comment from Arve on 2005-07-19 12:44
This parameter is one of the things I really don’t see the sensibility in passing: No live site I know of depends on this, and there is nothing useful to be done with this, except perhaps benchmarking Mozilla itself.
This discussion has been closed. No further comments may be added.