顺序为:
主线程 ---->微任务---->别的事件队列
微任务包括----->(promise mutation observe)
别的事件队列包括 ----->(setTimeout 点击 网络请求)
demoOne
console.log("script start"); setTimeout(function() { console.log("setTimeout---0"); }, 0); setTimeout(function() { console.log("setTimeout---200"); setTimeout(function() { console.log("inner-setTimeout---0"); }); Promise.resolve().then(function() { console.log("promise5"); }); }, 200); Promise.resolve() .then(function() { console.log("promise1"); }) .then(function() { console.log("promise2"); }); Promise.resolve().then(function() { console.log("promise3"); }); console.log("script end");
结果为
script start script end promise1 promise3 promise2 setTimeout---0 setTimeout---200 promise5 inner-setTimeout---0
demoTwo
console.log("script start"); setTimeout(function() { console.log("setTimeout---5000"); }, 5000); setTimeout(function() { console.log("setTimeout---0"); setTimeout(function() { console.log("inner-setTimeout---2000"); },2000); Promise.resolve().then(function() { console.log("promise5"); }); }, 0); console.log("script end");
结果为
script start script end setTimeout---0 promise5 inner-setTimeout---2000 setTimeout---5000
标签:function,事件处理,顺序,浏览器,log,script,---,console,setTimeout From: https://www.cnblogs.com/guohanting/p/16741629.html