Created
May 24, 2012 20:49
-
-
Save kennethlove/2784153 to your computer and use it in GitHub Desktop.
Deferedorator
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
var Deferedorator = function(col, func) { | |
_.extend(this, Backbone.Events); | |
this.collection_ = col; | |
this.function_ = func; | |
}; | |
Deferedorator.prototype.start = function() { | |
this.doItem_(0); | |
}; | |
Deferedorator.prototype.doItem_ = function(i) { | |
_.defer(this.doFunction_, i); | |
}; | |
Deferedorator.prototype.doFunction_ = function(i) { | |
var item = this.collection_[i]; | |
this.function_(item); | |
if (!this.collection_[i+1]) { | |
this.trigger("finished"); | |
return; | |
} | |
this.doItem_(i+1); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment