On 26/05/2005 23:25, JS wrote:
[snip]
var args = createOpts.arguments.length;
This should be
var args = arguments.length;
The arguments object should be accessed directly, not via a function object.
Is it correct that args holds the number of options that the selectobject
contains??
No. The arguments object represents the arguments passed to a function
when it's called. It will look like an array, but it isn't: it only has
two named properties, length and callee, and a series of numbered
properties starting at zero (0). For example,
/* Declaration */
function myFunction(arg0, arg1) {}
/* Call */
myFunction('string', 15, false);
The function, myFunction, is called with three arguments, but there are
only two named (or formal) arguments in the declaration. So, how do we
access the third? Using the arguments object.
In this example, arguments will have five properties in total:
arguments[0] The value of the first argument (arg0): 'string'
arguments[1] ...of the second argument (arg1): 15
arguments[2] ...of the third (it has no name): false
arguments.length The number of arguments passed to the function: 3
arguments.callee A reference to the function, myFunction, itself.
Does that make sense?
Presumably, createOpts allows any number of extra arguments after the
first one, sel. These extra arguments will probably be the display text
and values for the new OPTION elements. Rather than creating a long,
pointless list like
function createOpts(sel, text1, value1, text2, value2, ...) {}
which become almost impossible to work with, it just takes the extra
arguments from the arguments object.
Mike
--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.