window.setInterval是否有最大延迟限制 [英] Is there a maximum delay limit for window.setInterval
问题描述
今天我遇到了window.setInterval的一个有趣问题。当使用足够大的延迟(在这种情况下是30天内的毫秒数)时,它每秒执行一次而不是每30天执行一次。在最新的Chrome和Firefox中测试过。
Today I encountered an interesting problem with window.setInterval. When used with a sufficiently large delay (in this case the number of milliseconds in 30 days) it executes every second instead of every 30 days. Tested in latest Chrome and Firefox.
window.setInterval(function() {
document.getElementById("first").innerHTML = new Date().toString();
}, 5000);
window.setInterval(function() {
document.getElementById("second").innerHTML = new Date().toString();
}, 2592000000);
我找不到关于setInterval中延迟最大值的任何权威文档,以及< a href =https://developer.mozilla.org/en-US/docs/Web/API/WindowTimers/setInterval =noreferrer> MDN文档没有提及任何内容。其他在线资料表明,延迟应该能够容纳任何带符号的32位整数。
I couldn't find any authoritative documentation on the max value of a delay in setInterval, and the MDN documentation doesn't mention anything. Other sources online suggest that delay should be able to accommodate any signed 32-bit integer.
window.setInterval中的delay参数是否具有最大值,它是什么?
Does the delay parameter in window.setInterval have a maximum value and what is it?
推荐答案
根据 setTimeout
关于公共维基MDN的文档确实有最大值,虽然看起来并不正式 - 限制是一个带符号的32位整数。
According to the setTimeout
documentation on the public wiki MDN there is indeed a maximum, though it doesn't seem "official" - the limitation is a signed 32 bit integer.
最大延迟值
浏览器包括Internet Explorer,Chrome,Safari和Firefox
在内部将延迟存储为32位有符号整数。当使用大于2147483647的延迟时,这会导致
整数溢出,导致超时立即执行
。
Maximum delay value
Browsers including Internet Explorer, Chrome, Safari, and Firefox store the delay as a 32-bit signed integer internally. This causes an integer overflow when using delays larger than 2147483647, resulting in the timeout being executed immediately.
2592000000
的值确实大于 2147483647
因此导致溢出。
The value of 2592000000
is indeed larger than 2147483647
thus causing the overflow.
这篇关于window.setInterval是否有最大延迟限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!