Created
September 6, 2011 15:46
-
-
Save eriwen/1197927 to your computer and use it in GitHub Desktop.
Function chaining without Array prototype modifications
This file contains hidden or 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 chaining without modifying Array prototype. Not ES5 compatible. | |
* @param functions {Array{Function}} functions to schedule | |
* @param context {Object} for execution | |
*/ | |
function schedule(functions, context){ | |
setTimeout(function(){ | |
var process = functions.shift(); | |
process.call(context); | |
if (functions.length > 0){ | |
setTimeout(arguments.callee, 100); | |
} | |
}, 100); | |
} | |
// Example usage | |
schedule([doSomething, doSomethingElse, doOneMoreThing], window); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment