“`”
参考回答:
<pre><code class=""language-javascript"" lang=""javascript"">setTimeout(function(){console.log(1)},0);
new Promise(function(resolve,reject){
console.log(2);
resolve();
}).then(function(){console.log(3)
}).then(function(){console.log(4)});
process.nextTick(function(){console.log(5)});
console.log(6);
</code></pre>
//输出2,6,5,3,4,1
为什么呢?具体请参考我的文章:<a href=""https://github.com/forthealllight/blog/issues/5"">
从promise、process.nextTick、setTimeout出发,谈谈Event Loop中的Job queue</a>
<pre><code> "“`
Was this helpful?
0 /
0