题解 | #计时器#

计时器

https://www.nowcoder.com/practice/72c661d926494bd8a50608506915268c

function count(start, end) {
    let timeout_id
    let cancel = false 
    function doPoint(number) {
        console.log(number)
        if(number === end) {
            cancel = true
        }
        if(cancel) {
            return ;
        } else {
            timeout_id = setTimeout(() => doPoint(number+1), 100) 
        }
    }
    doPoint(start)
    return {
        cancel: function() {
            clearTimeout(timeout_id)
        }
    }
}

全部评论

相关推荐

陌夏微秋:一线城市25w左右吧,17×15=255
点赞 评论 收藏
分享
评论
2
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务