Keyboard shortcuts

Press ← or → to navigate between chapters

Press ? to show this help

Press Esc to hide this help

Number setTimeout(Function callback, Number delay, Any rest)

设定一个定时器。在定时到期以后执行注册的回调函数。

参数

参数类型默认值必填说明
callbackFunction是回调函数
delayNumber是延迟的时间,函数的调用会在该延迟之后发生,单位 ms。
argsAny否param1, param2, ..., paramN 等附加参数,它们会作为参数传递给回调函数。

返回值

类型说明
Number定时器的编号。这个值可以传递给 clearTimeout 来取消该定时。

示例代码:

const timeoutID = setTimeout(function(param1, param2){
    console.log('1秒后执行', param1, param2);
}, 1000, 'value1', 'value2');