Skip to content

Instantly share code, notes, and snippets.

@Ifmr24
Created April 24, 2020 01:29
Show Gist options
  • Save Ifmr24/3546ac4d0d7fa12519a2d82977f9c363 to your computer and use it in GitHub Desktop.
Save Ifmr24/3546ac4d0d7fa12519a2d82977f9c363 to your computer and use it in GitHub Desktop.
timer with pause
class Timer {
constructor() {
this.time = 0;
this.interval = -1;
}
start() {
if (this.interval === -1) {
this.interval = setInterval(() => {
this.time++;
}, 1000);
}
}
pause() {
clearInterval(this.interval);
this.interval = -1;
}
seconds() {
return this.time;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment