Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

setTimeout(fun) with a single argument? (Timeout not specified)

The HTML5 specifications states that setTimeout can be run without the additional "timeout" argument which is supposed to say after how many milliseconds will the function "handler" be scheduled.

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

However, I failed to find anywhere which explains what happens when no "timeout" time period is set.

An example usage is, the animation implementation int the Raphael library.

animationElements[length] && win.setTimeout(animation);
like image 719
Elazar Leibovich Avatar asked Apr 27 '10 17:04

Elazar Leibovich


People also ask

How many arguments will setTimeout take?

The setTimeout() function accepts two arguments. The first argument is a function and the second argument is time in milliseconds.

What happens when setTimeout is 0?

setTimeout(fn, 0) !== 0ms. When working with timers, setting a delay of 0, does not equate to 0ms or “instant” execution. This longer than expected delay may occur because the OS/browser/system is busy with other tasks or because the timer has been throttled.

How many times does setTimeout () execute the function parameter?

The JS setTimeout() method will call a function after the time specified in milliseconds (1000 ms = 1 second) has passed. The specified function will be executed once.

What is the difference between setTimeout FN 0 vs setImmediate FN?

setTimeout(,0) essentially means execute after all current functions in the present queue get executed. No guarantees can be made about how long it could take. setImmediate is similar in this regard except that it doesn't use queue of functions. It checks queue of I/O eventhandlers.


1 Answers

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

  1. Let timeout be the second argument to the method, or zero if the argument was omitted.
like image 51
Adam Wright Avatar answered Nov 13 '22 12:11

Adam Wright