Skip to content

Instantly share code, notes, and snippets.

@joewagner
Created April 26, 2014 17:36
Show Gist options
  • Save joewagner/11326170 to your computer and use it in GitHub Desktop.
Save joewagner/11326170 to your computer and use it in GitHub Desktop.
A class that runs a function on an interval. An instance of this class can be passed to many controllers, but only one interval will ever be set.
var RingOfPower = function (action, freq) {
if (typeof action === "undefined" || typeof freq === "undefined") {
throw new Error("must provide a function and an interval");
}
this.action = action;
this.frequency = freq;
};
RingOfPower.prototype.wield = function () {
clearInterval(this.interval);
this.interval = setInterval(this.action, this.frequency);
};
RingOfPower.prototype.conceal = function () {
clearInterval(this.interval);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment