Skip to content

Instantly share code, notes, and snippets.

@felipeelias
Created July 29, 2009 01:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save felipeelias/157805 to your computer and use it in GitHub Desktop.
Save felipeelias/157805 to your computer and use it in GitHub Desktop.
var Interval = function( fn, delay ) {
this.id = null;
this.fn = fn;
this.delay = delay;
};
Interval.prototype = {
start: function() {
if (this.id === null) this.id = setInterval(this.fn, this.delay);
return this;
},
stop: function() {
clearInterval(this.id);
this.id = null;
return this;
},
started: function() {
return this.id !== null;
}
};
var numero_de_execucoes = 1;
var i = new Interval(function() {
if(numero_de_execucoes >= 10 && i.started()) i.stop();
console.log(numero_de_execucoes++);
}, 1000);
i.start();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment