首頁 > web前端 > js教程 > 主體

為什麼我的'setTimeout”函數呼叫立即執行?

Linda Hamilton
發布: 2024-11-15 13:25:03
原創
541 人瀏覽過

Why is my `setTimeout` function call executing immediately?

Why is my function call scheduled by setTimeout executed 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);
    登入後複製

以上是為什麼我的'setTimeout”函數呼叫立即執行?的詳細內容。更多資訊請關注PHP中文網其他相關文章!

來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
作者最新文章
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板