javascript setInterval

前端 未结 8 1605
时光说笑
时光说笑 2020-11-30 12:30

a question. If i use setInterval in this manner:

setInterval(\'doSome();\',60000);

am i safe that the doSome() function is tri

8条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-30 13:12

    No, you are not guaranteed exact time safety. JS is event based (and single-threeaded) so the event won't fire at the exact right moment, especially not if you have other code running at the same time on your page.

    The event will fire in the neighbourhood of the set time value, but not on the exact millisecond. The error may be tens of milliseconds even if no other event is running at the time. This may be an issue if for example you have a long-running process where the timing is important. If you do, you'll need to synchronize with a clock once in a while.

提交回复
热议问题