0
我想在撥打this.start
時每this.delay
ms打電話this.cycle
。 當然,這是行不通的:在setInterval中執行this.function
function Timer(delay, repetitions){
this.delay = delay;
this.maxrep = repetitions;
this.rep = 0;
this.start = function(){
this.interval = setInterval(function(){
this.cycle();
},this.delay);
}
this.cycle = function(){
this.rep++;
console.log(this.rep);
if(this.rep >= this.max){
clearInterval(this.interval);
}
}
}
謝謝!我不習慣箭頭功能,這就是爲什麼。 – AlreadyAlreadyTaken