模拟 setInterval

目的:避免 setInterval 因执行时间导致的间隔执行时间不一致。

arguments.callee

setTimeout(function () {
  console.log(new Date())
  setTimeout(arguments.callee, 1000)
}, 0)

注意argument 已经从 Web 标准中删除,并且在严格模式('use strict')下,不能使用 arguments.callee

递归 + setTimeout()

function infinite() {
  console.log(new Date())
  return setTimeout(infinite, 1000)
}

infinite()
全部评论

相关推荐

10-14 12:20
门头沟学院 Java
迷茫的大四🐶:摊牌了,我是25届的,你们也不招我
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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