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