setInterval(callback[, delay[, ...args]])


  • callback <Function> 计时器到期时要调用的函数。
  • delay <number> 在调用 callback 之前要等待的毫秒数。默认值: 1
  • ...args <any> 调用 callback 时可传入的可选参数。
  • 返回:<Timeout>clearInterval() 使用

安排 callback 每隔 delay 毫秒重复执行。

🌐 Schedules repeated execution of callback every delay milliseconds.

delay 大于 2147483647 或小于 1 时,delay 将被设置为 1。非整数的延迟将被截断为整数。

🌐 When delay is larger than 2147483647 or less than 1, the delay will be set to 1. Non-integer delays are truncated to an integer.

如果 callback 不是一个函数,将会抛出 TypeError

🌐 If callback is not a function, a TypeError will be thrown.

这种方法有一个适用于 Promise 的自定义变体,可以通过 timersPromises.setInterval() 使用。

🌐 This method has a custom variant for promises that is available using timersPromises.setInterval().