setTimeout(myFunction, 5000); vs setTimeout(myFunction(), 5000);

后端 未结 3 857
忘了有多久
忘了有多久 2021-01-21 13:27

I was playing around with the \"setTimeout\" function. This code runs like expected:

function myFunction() {
    console.log(\'test\');
    setTimeout(myFunction         


        
3条回答
  •  青春惊慌失措
    2021-01-21 14:04

    That is because by including the parentheses you're actually executing the function and passing its result to setTimeout.

提交回复
热议问题