Possuo essa classe, estou com dificuldade de pausar o cronometro através de uma instancia.
Não estou conseguindo me referir ao setInterval através das instancias dessa classe.
var c = new Chronometer(1, 0, 0, 0);
c.start()
c.pause()
Ao chamar o c.pause() preciso que ele pause o setInterval dessa instancia.
class Chronometer {
constructor(id, h, m, s) {
this.id = id;
this.h = h;
this.m = m;
this.s = s + 1;
}
start() {
setInterval(() => {
if (this.s == 60) { this.m++; this.s = 0; }
if (this.m == 60) { this.h++; this.s = 0; this.m = 0; }
if (this.s < 10) {
document.getElementById("modalsecond_" + this.id).innerHTML = "0" + this.s;
} else {
document.getElementById("modalsecond_" + this.id).innerHTML = this.s;
}
if (this.h < 10) {
document.getElementById("modalhour_" + this.id).innerHTML = "0" + this.h;
} else {
document.getElementById("modalhour_" + this.id).innerHTML = this.h;
}
if (this.m < 10) {
document.getElementById("modalminute_" + this.id).innerHTML = "0" + this.m;
} else {
document.getElementById("modalminute_" + this.id).innerHTML = this.m;
}
this.s++;
}, 1000);
}
pause() {
clearInterval(this)
}
}