Hi jQuerians,

I'm wondering what is the best way to concatenate (callback) functions.

The problem: I call a certain function several times passing in a 
function reference that is used as a callback. All callbacks will be 
used in one large callback in the end but I cannot build the callback at 
once.

initialize(funcRef);
...
initialize(anotherFuncRef);

function initialize(callback) {
     // concatenate callbacks from different calls
}

What would be the most elegant way to do this? I had the idea to store 
the functions in a list and call them one after the other in a loop.

The other idea I had is this:

var myCallback;
function initialize(callback) {
     if (myCallback) {
         myCallback = function() {
             myCallback();
             callback();
         }
     } else {
         myCallback = callback;
     }
}

Hm, that doesn't convince me either. Both ideas make me think there is a 
more elegant way to achieve this. Is there a better pattern from the 
gurus out there?

Thanks!


-- Klaus

_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/

Reply via email to