Skip to content

Instantly share code, notes, and snippets.

@eriwen
Created September 6, 2011 15:46
Show Gist options
  • Save eriwen/1197927 to your computer and use it in GitHub Desktop.
Save eriwen/1197927 to your computer and use it in GitHub Desktop.
Function chaining without Array prototype modifications
/**
* 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