Currently, I am delving into JavaScript animations and utilizing multiple functions to add components to the animation queue. The structure of these functions is quite repetitive as shown below:
function foo(arg1, arg2) {
_eventQueue.push(function() {
// actual logic
}
}
However, I have been contemplating ways to minimize this redundancy to avoid repeatedly including the "_eventQueue" line in each function. Is there a way to create a helper function that can take any function as an argument and return a new function augmented to automatically join the event queue? My main obstacle lies in retaining access to the original function's arguments during this process, which poses a challenge.