Skip to content

Instantly share code, notes, and snippets.



Forked from gengkev/interval.js
Created Feb 22, 2012
What would you like to do?
Accurate Javascript setInterval replacement
function Interval(func,duration){
if(typeof func !== "function") throw new TypeError("Expected function");
else if(typeof duration !== "number") throw new TypeError("Expected number");
this.func = func;
this.duration = duration;
this.baseline = +new Date();
_this.timer = setTimeout(function(){;
}; = function(){;
this.baseline += this.duration;
var nextTick = this.duration + this.baseline - new Date();
if(nextTick<0) nextTick = 0;
_this.timer = setTimeout(function(){;
Interval.prototype.stop = function(){
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.