A doubt about the case in the "callback" chapter of "JavaScript you don't know" (related to (setTimeout ())

topic description

Programs in

setTimeout () run ahead of time. Under normal circumstances, shouldn"t the setTimeout () function be executed after all execution has been completed in the current stack?

sources of topics and their own ideas

the case in the book "JavaScript you don"t know" is rewritten. In fact, I don"t have a thorough understanding of this case.

related codes

   

Apr.08,2021

execute asyncify (result) first, decompose the timer step, and you should be able to understand it.

var a = 0;
var timeoutFn = asyncify(result);
var b = setTimeout(timeoutFn,100);

aPP;
console.log('end');

because asyncify (result) is executed first.


you think
setTimeout (fn, 100)
fn is a defined function, which is executed after 100ms
but if you write it as setTimeout (fn (), 100) this is a function called by itself, the fn function will be executed immediately, and
will execute the function after fn return

after 100ms.
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3b956-2ba22.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3b956-2ba22.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?