setTimeout(callback[, delay[, ...args]])
-
callback
<Function> 当定时器结束时调用的函数。¥
callback
<Function> The function to call when the timer elapses. -
delay
<number> 调用callback
之前等待的毫秒数。默认值:1
。¥
delay
<number> The number of milliseconds to wait before calling thecallback
. Default:1
. -
...args
<any> 调用callback
时要传入的可选参数。¥
...args
<any> Optional arguments to pass when thecallback
is called. -
返回:<Timeout> 与
clearTimeout()
配合使用¥Returns: <Timeout> for use with
clearTimeout()
在 delay
毫秒后调度单次的 callback
的执行。
¥Schedules execution of a one-time callback
after delay
milliseconds.
callback
可能不会在精确的 delay
毫秒内被调用。Node.js 不保证回调将触发的确切时间,也不保证它们的顺序。回调将在尽可能接近指定的时间时调用。
¥The callback
will likely not be invoked in precisely delay
milliseconds.
Node.js makes no guarantees about the exact timing of when callbacks will fire,
nor of their ordering. The callback will be called as close as possible to the
time specified.
当 delay
大于 2147483647
或小于 1
或 NaN
时,delay
将设置为 1
。非整数延迟被截断为整数。
¥When delay
is larger than 2147483647
or less than 1
or NaN
, 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.
此方法具有可使用 timersPromises.setTimeout()
获得的 promise 的自定义变体。
¥This method has a custom variant for promises that is available using
timersPromises.setTimeout()
.