间隔太慢
Interval is too slow
间隔不是每毫秒 运行ning 一次。最后的数字只达到 459 就停止了。如果间隔上不止一条线,则更少。在这里它甚至没有经过前一千。我想要的是每秒 运行 一次,让我知道间隔完成了多长时间。所以如果 testNum
是 30,那么我知道它已经完成了 97% (2970/3000)
。
let testNum = 3000
let testInt = setInterval(() => {
testNum--
}, 1)
let testTimeout = setTimeout(() => {
clearInterval(testInt)
console.log('Final Number: ' + testNum)
}, 3000)
来自https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/setInterval#Parameters:
delay
The time, in milliseconds (thousandths of a second), the timer should delay in between executions of the specified function or code. If this parameter is less than 10, a value of 10 is used.
间隔不是每毫秒 运行ning 一次。最后的数字只达到 459 就停止了。如果间隔上不止一条线,则更少。在这里它甚至没有经过前一千。我想要的是每秒 运行 一次,让我知道间隔完成了多长时间。所以如果 testNum
是 30,那么我知道它已经完成了 97% (2970/3000)
。
let testNum = 3000
let testInt = setInterval(() => {
testNum--
}, 1)
let testTimeout = setTimeout(() => {
clearInterval(testInt)
console.log('Final Number: ' + testNum)
}, 3000)
来自https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/setInterval#Parameters:
delay
The time, in milliseconds (thousandths of a second), the timer should delay in between executions of the specified function or code. If this parameter is less than 10, a value of 10 is used.