JavaScript setInterval immediately run

前端 未结 5 1900
梦如初夏
梦如初夏 2021-01-22 09:28

I found a solution to run interval in javascript immidiately, not waiting for a first \"timeout\"

setInterval(function hello() {
  console.log(\'world\');
  retu         


        
5条回答
  •  没有蜡笔的小新
    2021-01-22 10:13

    If you add the parenthesis to the below code part it does

        doMagic: function () {
            setInterval(function magic() {
                console.log('magic');
                return magic;
            }(), 2500);                   // added them here
        }
    

提交回复
热议问题