Created
September 6, 2011 15:35
-
-
Save eriwen/1197883 to your computer and use it in GitHub Desktop.
Simple function chaining with a timeout (not ES5 compatible)
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
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