public
Created

Simple function chaining with a timeout (not ES5 compatible)

  • Download Gist
chain.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13
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();

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.