javascript setInterval

前端 未结 8 1603
时光说笑
时光说笑 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:10

    Yes, the browser's focus is irrelevant.

    However, you should not use a string argument to setInterval. Use a reference to the function instead:

    setInterval(doSome, 60000);
    
    0 讨论(0)
  • 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.

    0 讨论(0)
提交回复
热议问题