簡體   English   中英

setTimeout 立即運行 function

[英]setTimeout runs function immediately

我正在嘗試在一段時間后使用“setTimeout”運行“window.open”function。 如果我用父屬性計算時間差,然后將 output 用於“setTimeout”,則“window.open”function 會立即運行。 但是,如果我只是給變量“diffms”一個數字,它就可以正常工作。 我正在使用反應,我該如何解決這個問題?

// const diffms = 10000;
const diffms = moment(this.props.schedule.time).diff(moment());
  setTimeout(() => {
    window.open("https://www.google.com");
}, diffms);

SetTimeout 具有Maximum Delay Value

包括 Internet Explorer、Chrome、Safari 和 Firefox 在內的瀏覽器在內部將延遲存儲為 32 位簽名的 integer。

當使用大於 2,147,483,647 毫秒(約 24.8 天)的延遲時,這會導致 integer 溢出,從而導致立即執行超時。

請在此處查看更多詳細信息:

https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/setTimeout#:~:text=Maximum%20delay%20value&text=This%20causes%20an%20integer%20overflow,the%20timeout%20being %20立即執行%20

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM