javascript - About setTimeout issues
过去多啦不再A梦
过去多啦不再A梦 2017-05-19 10:22:28
0
2
377

I don’t understand why time using is always 5000ms? Why do I always think the first one is 6000 and the second one is 7000?

过去多啦不再A梦
过去多啦不再A梦

reply all(2)
黄舟

This is the case. The delay time of setTimeout is relative to the time when it is called. The first blocking time of 1000ms in while is included in the 5000 of setTimeout. After the second 5000ms is executed similarly, it It will be judged whether the delay time of setTimeout at this time has passed 2000ms compared to before. If it has passed, it will be executed immediately. In fact, the time using time is the value of MAX (setTimeout, while ())

大家讲道理

Although settimeout will be pushed onto the stack, the delay time will not change. As long as there is no blocking and the time is reached, the first blocking 1000ms will be executed, and then the 1000ms of the blocking delayed by 5000ms will be included. The second blocking will be executed after 5000ms. Execute immediately and delay 2000ms

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template