Time out



  • The code the outside library showed.
    What thin points could make the author time zero?

    setTimeout(function () {
        //todo something
    }, 0);
    


  • This may be necessary if the code is to be asynchronous.

    For example

       console.log("1");
       console.log("2");
       console.log("3");
    

    will, as expected: 1 2 3

    However, when appended setTimeout It'll work. 1 3 2

    console.log("1");
    setTimeout(function() {
        console.log("2");
    }, 0);
    console.log("3"); // > 1 3 2
    

    This is because the function is postponed until the next turn. event loop


Log in to reply
 


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2