JavaScript : putting a function into a variable and executing it

スポンサーリンク

 

  start();
  function start(){

    notwork = function test2(){
      console.log('This doesn't work');
      start();
    }

  }

This one doesn’t work because test2 function cannot start automatically.

 

  start();
  function start(){

    timer = setTimeout(function(){
      console.log('yes, it works');
      start();
    }, 200);

  }

This one works because setTimeout start automatically.

タイトルとURLをコピーしました