setInterval() behaviour with 0 milliseconds in JavaScript

前端 未结 4 977
孤独总比滥情好
孤独总比滥情好 2020-11-27 21:18

In my application I found some JavaScript code that is using setInterval with 0 milliseconds, like so:

self.setInterval(\"myFunction()\",0);
         


        
4条回答
  •  醉酒成梦
    2020-11-27 21:39

    I assume that in myFunction() there is a clearInterval.

    Basically, you've set an interval that can happen as often as possible. If the browser executing JavaScript actually gets to the clearInterval part before the next iteration of the interval, then it will be fine. Otherwise, it will happen again and again.

    Use setTimeout instead.

提交回复
热议问题