猫史档案馆


【代码】升级后的计算器API

用户:星星上的雪花星星上的雪花查看: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: 计时暂停

星星上的雪花 首发编程猫社区


回复

上一页1 页 / 共 1下一页
浮生awa浮生awa

nb!!!!!!!!!!!!好用的很

点赞0


评论


屑student屑student

nb

点赞0


评论


async_functionasync_function

(小声bb:constructor的bug我修的())

点赞2


评论


憨白不憨awa憨白不憨awa

666

 

点赞0


评论


灵清帝王吃爆一切厕所灵清帝王吃爆一切厕所

看不懂了)、

点赞0


评论


外向的雷电猴-LHA外向的雷电猴-LHA

666

点赞0


评论


翎with珝翎with珝

挖坟((((

点赞0


评论


小鹿UUyM小鹿UUyM

挖 

点赞0


评论


box3的果敢的超能鸭viwXbox3的果敢的超能鸭viwX

nb!

点赞0


评论