Execute the setInterval function without delay the first time

后端 未结 14 2347
故里飘歌
故里飘歌 2020-11-22 16:17

It\'s there a way to configure the setInterval method of javascript to execute the method immediately and then executes with the timer

14条回答
  •  星月不相逢
    2020-11-22 16:35

    actually the quickest is to do

    interval = setInterval(myFunction(),45000)
    

    this will call myfunction, and then will do it agaian every 45 seconds which is different than doing

    interval = setInterval(myfunction, 45000)
    

    which won't call it, but schedule it only

提交回复
热议问题