Skip to content

Instantly share code, notes, and snippets.

@mkuklis
Created April 22, 2013 19:17
Show Gist options
  • Save mkuklis/5437711 to your computer and use it in GitHub Desktop.
Save mkuklis/5437711 to your computer and use it in GitHub Desktop.
interval mixin
function intervalMixin() {
var intervals = [];
return {
addInterval: function (func, delay) {
intervals.push({ func: func.bind(this), delay: delay });
},
startIntervals: function () {
intervals.forEach(function (interval) {
interval.id = setInterval(interval.func, interval.delay);
});
},
stopIntervals: function () {
intervals.forEach(function (interval) {
clearInterval(interval.id);
});
},
clearIntervals: function () {
this.stopIntervals();
intervals = [];
}
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment