function SetInterval(callback, time) {
let that=this;
this.start = new Date().getTime();
this.end;
this.offset;
this.loopNum = 0;
this.timeoutTag = null;
this.time = time;
this.callback = callback;
this.set(time);
this.clear=function(){
clearTimeout(that.timeoutTag);
that.timeoutTag = undefined;
console.log("清除定时器----")
}
}
SetInterval.prototype.set = function (_time) {
var that = this;
if (this.timeoutTag === undefined) return;
clearTimeout(this.timeoutTag);
this.timeoutTag = null;
that.timeoutTag = setTimeout(function () {
that.loopNum++;
that.end = new Date().getTime();
that.callback();
that.offset = that.end - that.start - that.time * that.loopNum;
if (that.offset > 0) {
that.set(that.time - that.offset);
} else if (that.offset < 0) {
that.set(that.time + that.offset);
} else {
that.set(that.time);
}
}, _time);
};
module.exports={
SetInterval,
}