Skip to content

Instantly share code, notes, and snippets.

@eriwen
Created September 6, 2011 15:35
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eriwen/1197883 to your computer and use it in GitHub Desktop.
Save eriwen/1197883 to your computer and use it in GitHub Desktop.
Simple function chaining with a timeout (not ES5 compatible)
Array.prototype.chain = function chain(delay) {
var tasks = this, pos = 0, delay = delay || 17;
setTimeout(function() {
tasks[pos++]();
if (pos < tasks.length) setTimeout(arguments.callee, delay);
}, delay);
return this;
};
// Usage;
var tasks = [];
tasks.push(func);
tasks.chain();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment