I would like to write a javascript function that works something like this…
f([["a"]], function(e){alert(e);});
// results in alert("a");
f([["a"], ["b"]], function(e1,e2){alert(e1 + ":" + e2);});
//results in alert("a:b");
f([["a", "b"], ["c"]], function(e1,e2){alert(e1 + ":" + e2);});
//results in alert("a:c");alert("b:c");
I can think of a recursive solution for the looping, but how do I send a “unknown” number of variables to a function?
If you put all your arguments into an array (lets call it
foo), you can call a functionfnwith those arguments by using theapply-function.The first argument (
nullin this case) is whatever you wantthisto be inside of the called function.nullwill probably work for you.