Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

setTimeOut issues in Firefox

Why doesn't the following work in Firefox (v16)?

var t = setTimeout(foo(), 1000);

The error I get in the console is: "useless setTimeout call (missing quotes around argument?)". Wrapping it in quotes doesn't seem to do much, except making it render as a string (unsurprisingly).

It does however work fine when I wrap it in an anonymous function like so:

var t =
    setTimeout(function(){
       foo();
     }, 1000);

But why is it necessary? Why doesn't it explode in Webkit or Opera? Stroke of luck?

like image 427
Nix Avatar asked Sep 23 '26 04:09

Nix


1 Answers

Its because you are invoking foo in your first example.

Its basically the same as doing this:

var tempResultOfFoo = foo();
var t = setTimeout(tempResultOfFoo, 1000);
like image 119
Daniel A. White Avatar answered Sep 24 '26 19:09

Daniel A. White



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!