Any better way to combine multiple callbacks?
I need to call an async function (with loop) for multiple values and wait for those results. Right now I'm using the following code: (function(){ var when_done = function(r){ alert("Completed. Sum of lengths is: [" + r + "]"); }; // call when ready var datain = ['google','facebook','youtube','twitter']; // the data to be parsed var response = {pending:0, fordone:false, data:0}; // control object, "data" holds summed response lengths response.cb = function(){ // if there are pending requests, or the loop isn't ready yet do nothing if(response.pending||!response.fordone) return; // otherwise