Promise principle and setTimeout sequence problem

see many promise implementations on the Internet using setTimeout to adjust the execution order
since they are all based on setTimeout, why is promise faster than setTimeout?

I understand the difference between micro and macro tasks
but isn"t promise based on setTimeout?

Jul.14,2021

clipboard.png

promise is promise, setTimeout is setTimeout, but in some cases, for example, if the browser does not support promise, use setTimeout to cover the bottom. For example, nextTick


native promise in vue does not need setTimeout


Promise is a solution for asynchronous programming. It was first proposed and implemented by the community, and ES6 wrote it into the language standard, unified usage, and natively provided Promise objects. http://es6.ruanyifeng.com/-sharpdo.


setTimeout only simulates the asynchronous process, and Promise is used to solve asynchronous processing

Menu