Skip to content

Instantly share code, notes, and snippets.

@brianewing
Created January 1, 2012 23:36
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 brianewing/1548659 to your computer and use it in GitHub Desktop.
Save brianewing/1548659 to your computer and use it in GitHub Desktop.
Timer - utility class for controlling intervals
function Timer(func, delay, start) {
this.func = func;
this.delay = delay;
this.running = false;
if(start) this.start();
}
Timer.prototype.start = function(delay) {
this.running = true;
return this.interval = setInterval(this.func, (delay || this.delay));
}
Timer.prototype.stop = function() {
this.running = false;
clearInterval(this.interval);
}
// timer = new Timer(function() { }, 1000); timer.start(); timer.running == true; timer.stop();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment