Skip to content

Instantly share code, notes, and snippets.

@kane-thornwyrd
Created October 31, 2013 10:51
Show Gist options
  • Save kane-thornwyrd/7247769 to your computer and use it in GitHub Desktop.
Save kane-thornwyrd/7247769 to your computer and use it in GitHub Desktop.
var multiAction = function(action, nb, delay){
this.action = action;
this.nb = nb;
this._nb = this.nb;
this.delay = delay;
}
multiAction.prototype = {
_iterate: function(){
if(--this._nb <= 0){
this.shutdown();
}
},
fire: function(el){
if(this._nb <= 0){
this._nb = this.nb;
}
if(typeof this._interval === 'undefined'){
this._interval = setInterval(
this.action.bind(this, el, this._iterate.bind(this)),
this.delay
);
}
},
shutdown: function(){
clearInterval(this._interval);
this._interval = undefined;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment