owtlab-tracking
Version:
A simple Tracking system
31 lines (26 loc) • 532 B
JavaScript
export function timer(num) {
if (this instanceof timer === false) {
return new timer(num);
}
this.count = num || 0;
return this;
}
timer.prototype.start = function () {
const self = this;
this.pause();
this.interval = setInterval(() => {
self.count++;
}, 1000);
return this;
};
timer.prototype.pause = function () {
clearInterval(this.interval);
return this;
};
timer.prototype.value = function () {
return this.count;
};
timer.prototype.clear = function () {
this.count = 0;
return this;
};