setTimeout or setInterval?

前端 未结 19 3518
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-21 04:59

As far as I can tell, these two pieces of javascript behave the same way:

Option A:

function myTimeoutFunction()
{
    doStuff();
           


        
19条回答
  •  半阙折子戏
    2020-11-21 05:31

    The very difference is in their purposes.

    setInterval()
       -> executes a function, over and over again, at specified time intervals  
    
    setTimeout()
       -> executes a function, once, after waiting a specified number of milliseconds
    

    It's as simple as that

    More elaborate details here http://javascript.info/tutorial/settimeout-setinterval

提交回复
热议问题