Skip to content

Instantly share code, notes, and snippets.

@jineeshjohn
Last active August 29, 2015 13:59
Show Gist options
  • Save jineeshjohn/10725702 to your computer and use it in GitHub Desktop.
Save jineeshjohn/10725702 to your computer and use it in GitHub Desktop.
Asynchronous way of executing array of JavaScript functions
function f1(cb){
console.log("I am f1");
cb();
}
function f2(cb){
console.log("I am f2");
cb()
}
function f3(){
console.log("I am f3");
}
var runTasks = function(funcs, scope) {
(function Fn() {
if(funcs.length > 0) {
// var params = [Fn].concat(Array.prototype.slice.call(arguments, 0));
funcs.shift().call(scope || {}, Fn);
}
})();
};
var list = [f1,f2,f3];
runTasks(list);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment