用户:
星星上的雪花查看:3 回复:9 评论:3 创建时间:2021-12-18T09:20:37
class Box3Timed {
constructor() {
(async () => {
this.time = 0;
this.wait = false;
this.over = false;
while (!this.over){
await sleep(1);
if(this.wait)continue;
this.time += 1
}
})()
}
cancel() {
return this.over = true
}
stop() {
return this.wait = true
}
play() {
return this.wait = false
}
get() {
return this.time
}
}
实例:
const timer = new Box3Timed();//创建新计时器
timer.get(); //获取当前计时, 类型:数字, 单位:毫秒
timer.stop(); //暂停计时,但不终止计时
timer.play(); //在上次暂停计时的基础上继续计时
timer.cancel(); //不计时了, 终止计时
timer.over; //类型:布尔值, true: 计时终止
timer.wait; //类型:布尔值, true: 计时暂停
星星上的雪花 首发编程猫社区