setTimeout(fun)只有一个参数?(未指定超时)

Ela*_*ich 6 javascript settimeout

HTML5 规范,各国setTimeout可以在不这是应该经过多少毫秒将函数"处理程序"被安排说额外的"超时"的说法来运行.

handle = window . setTimeout( handler [, timeout [, arguments ] ] )
   Schedules a timeout to run handler after timeout milliseconds. Any arguments are passed straight through to the handler.
Run Code Online (Sandbox Code Playgroud)

但是,我没有找到解释当没有设置"超时"时间段时会发生什么的任何地方.

一个示例用法是Raphael库中的动画实现.

animationElements[length] && win.setTimeout(animation);
Run Code Online (Sandbox Code Playgroud)

Ada*_*ght 15

http://www.whatwg.org/specs/web-apps/current-work/multipage/timers.html#get-the-timeout

  1. 令timeout为该方法的第二个参数,如果省略该参数则为零.

  • 打败我:-) +1.我打算添加我自己的答案(但也可以在这里添加),因为超时参数为0并不一定意味着它会立即运行,当线程变为空闲时它仍将排队等待运行,例如在所有当前代码执行完成之后. (6认同)