Last active
August 29, 2015 13:59
-
-
Save jineeshjohn/10725702 to your computer and use it in GitHub Desktop.
Asynchronous way of executing array of JavaScript functions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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