Home > Article > Web Front-end > Why is my `setTimeout` function call executing immediately?
In an attempt to test proxy servers, a function titled crawl() has been devised. The objective is for this function to invoke doRequest() at intervals of roughly 10 seconds. However, despite employing setTimeout(), the function is being called immediately.
To remedy this, there are three viable solutions:
Alter the order of arguments:
setTimeout(doRequest, proxytimeout, url, proxys[proxy]);
Use an evaluable string:
setTimeout('doRequest('+url+','+proxys[proxy]+')', proxytimeout);
Pass an anonymous function:
(function(u, p, t) { setTimeout(function() { doRequest(u, p); }, t); })(url, proxys[proxy], proxytimeout);
The above is the detailed content of Why is my `setTimeout` function call executing immediately?. For more information, please follow other related articles on the PHP Chinese website!