Есть конструкция в ходе которой у объекта есть переменная interval и через методы в прототипе этой переменной задаётся setInterval и при нажатии на кнопку этот setInterval должен тормозиться, но этого почему-то не происходит.
class Timer{
constructor(date){
this.interval;
}
startCount() {
this.interval = setInterval(()=> console.log('work'), 100);
}
stopCount() {
clearInterval(this.interval);
}
}
let timer = new Timer();
timer.startCount();
document.querySelector('button').onclick = timer.stopCount;
<button> stop </button>
Попробуйте так:
class Timer {
constructor(date){
this.interval;
}
startCount() {
this.interval = setInterval(()=> console.log('work'), 300);
}
stopCount() {
clearInterval(this.interval);
}
}
var timer = new Timer();
document.querySelector('a').onclick = function(){
timer.startCount();
}
document.querySelector('button').onclick = function(){
timer.stopCount();
}
<a href="#"> start </a>
<button> stop </button>
Продвижение своими сайтами как стратегия роста и независимости