JavaScript Metaprogramming: Reduce boilerplate of adding functions to a function queue
Posted
by thurn
on Stack Overflow
See other posts from Stack Overflow
or by thurn
Published on 2010-04-22T19:31:01Z
Indexed on
2010/04/22
19:33 UTC
Read the original article
Hit count: 326
JavaScript
I'm working with animation in JavaScript, and I have a bunch of functions you can call to add things to the animation queue. Basically, all of these functions look like this:
function foo(arg1, arg2) {
_eventQueue.push(function() {
// actual logic
}
}
I'm wondering now if it would be possible to cut down on this boilerplate a little bit, though, so I don't need that extra "_eventQueue" line in the function body dozens of times. Would it be possible, for example, to make a helper function which takes an arbitrary function as an argument and returns a new function which is augmented to be automatically added to the event queue? The only problem is that I need to find a way to maintain access to the function's original arguments in this process, which is... complicated.
© Stack Overflow or respective owner