As of ColdFusion 8 we have been able to pass a struct into a method so it becomes the method's argument collection without knowing the individual keys in the struct.
In my instance I didn't care about the this scope (It can be a very handy way to simulate inheritance but that's another story) so I just passed in an empty object. Below I have an example which is simple enough not to make any real-world sense, but it gets the point across.
2 function foo()
4 for(var i=0; i<arguments.length; i++)
10 function callIt(callThis,passInThese)
16 <button onclick="callIt(foo,['Hello','World']);">Button 1</button>
17 <button onclick="callIt(foo,['Goodbye','Cruel','World']);">Button 2</button>
Both buttons will ultimately result in the foo function being called with two different set of arguments via the callIt function which knows nothing of foo nor its requirements.
A few notes:
- I cannot verify if there are any bad side effects of using apply() this way-- I just know it works.
- This may also be possible with the use of eval() but I like this better.
- I didn't specify the arguments to foo in its declaration, but there is nothing keeping you from doing it. If you did, you would be able to refer to your arguments by name as opposed to looping over the argument array like I did.