Is there a way to create a Javascript function that can accept a variable number of parameters and pass them on to other anonymous functions?
Let's consider an example scenario where a method needs to trigger an event:
function fireStartedEvent(a,b,c,d,e,f,g,...) {
for(var i = 0; i < startedListeners.length; i++) {
startedListeners[i](a,b,c,d,e,f,g,...);
}
}
Since I have a factory generating these event firing methods, it is not necessary for these methods to determine the exact number of parameters an event or its handlers may require. Currently, it is hardcoded at 7 (a through g). If fewer parameters are passed, no issue arises. However, if more parameters are provided, they are cut off. How can I capture and forward all parameters?
Appreciate any suggestions.
(Please note that using jQuery or any other JavaScript framework is not an option in this case.)