简体   繁体   English

如何在javascript中将超时设置为无穷大

[英]how to set a timeout to infinity in javascript

I have a timeout event that I want to set to infinity.我有一个我想设置为无穷大的超时事件。 Right now I just set it to 9999999 meaning that after that many milliseconds the event will trigger.现在我只是将它设置为9999999意味着在很多毫秒之后事件将被触发。 But it is not so elegant, what's a better way to make it infinite?但它不是那么优雅,有什么更好的方法让它无限?

There is no reason to trigger event after infinity time.无限时间后没有理由触发事件。 Doing that will make events stays in stack forever and they could pile up.这样做将使事件永远留在堆栈中,并且它们可能会堆积起来。

Correct approach:正确做法:

let booleanFlag = false;

// do somethinghing that can change "booleanFlag" value

function triggerThisOnSomeEvent(booleanFlag) {
    if (booleanFlag) {
        // Handle event
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM