How to make a promise from setTimeout

Update (2017) Here in 2017, Promises are built into JavaScript, they were added by the ES2015 spec (polyfills are available for outdated environments like IE8-IE11). The syntax they went with uses a callback you pass into the Promise constructor (the Promise executor) which receives the functions for resolving/rejecting the promise as arguments. First, since async … Read more

Why is my function call that should be scheduled by setTimeout executed immediately? [duplicate]

As you give the function to the setTimeout in that form, the function is executed instead of passed to the setTimeout. You have three alternatives to make it work: Give first the function, then the timeout and the parameters as the last arguments: setTimeout(doRequest, proxytimeout, url, proxys[proxy]); Or just write a string that will be … Read more

Difference between setTimeout with and without quotes and parentheses

Using setInterval or setTimeout You should pass a reference to a function as the first argument for setTimeout or setInterval. This reference may be in the form of: An anonymous function setTimeout(function(){/* Look mah! No name! */},2000); A name of an existing function function foo(){…} setTimeout(foo, 2000); A variable that points to an existing function … Read more