Execute the setInterval function without delay the first time

后端 未结 14 2168
故里飘歌
故里飘歌 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:26

    I'm not sure if I'm understanding you correctly, but you could easily do something like this:

    setInterval(function hello() {
      console.log('world');
      return hello;
    }(), 5000);
    

    There's obviously any number of ways of doing this, but that's the most concise way I can think of.

提交回复
热议问题