In Javascript I have simple test code:
function x(a, b) {
alert(a);
alert(b);
}
var c = [1,2];
x(c);
which send an argument c to function x() as one argument, assigned to a and b stays undefined :-/
How can I send an array as multiple arguments to a function, not as one array?
Check out
apply.In your case (since you aren’t using
thisin the function), you can simply passwindow(orthis) as the “this” argument:Example: http://jsfiddle.net/MXNbK/2/
Per your question about passing
nullas the “this” argument, see MDN’s comment in the linked article on the “this” argument: