我正在做一个Web应用程序: Pomodoro 。
我创建了一个课程。但是我无法访问此this.countdown = setInterval(timer,1000)
中的函数。
我写了“ this.timer”。这样,错误不会返回,但是函数无法正常工作。我该怎么办?
class Pomodoro{
constructor(){
this.countdown = 0;
this.seconds = 1500;
this.workTime = 25;
this.breakTime = 5;
this.isBreak = true;
this.isPaused = true;
this.minutes = Math.floor(this.seconds / 60);
this.remainderSeconds = this.seconds % 60;
};
start(){
clearInterval(this.countdown);
this.isPaused = !this.isPaused;
if(!this.isPaused){
this.countdown = setInterval(timer,1000);
};
};
reset(){
clearInterval(this.countdown);
this.seconds = this.workTime*60;
this.countdown = 0;
this.isBreak = true;
this.isPaused = true;
};
timer(){
this.seconds --;
if(this.seconds < 0){
clearInterval(this.countdown);
this.seconds = (this.isBreak ? this.breakTime : this.workTime) * 60;
}
};
}
let pomodoro = new Pomodoro();
function Update(){
pomodoro.start();
pomodoro.timer();
}
window.setInterval(Update, 100);