关于node.js的异步怎么去解释?

`

console.log('1');
setTimeout(function() {
console.log('2');
process.nextTick(function() {
    console.log('3');
})
new Promise(function(resolve) {
    console.log('4');
    resolve();
}).then(function() {
    console.log('5')
})
})
process.nextTick(function() {
console.log('6');
})
new Promise(function(resolve) {
    console.log('7');
    resolve();
}).then(function() {
    console.log('8')
})
setTimeout(function() {~~~~
console.log('9');
process.nextTick(function() {
    console.log('10');
})
new Promise(function(resolve) {
    console.log('11');
    resolve();
}).then(function() {
    console.log('12')
})
})

`
这个的运行结果是什么?
这是我的:1 6 2 3 4 5 7 8 10 9 11 12,
但是在node环境下是 :1 7 6 8 2 4 9 11 3 10 5 12,
不是很懂。请各位指点一二

阅读 1.7k
1 个回答

我的node环境是1 7 6 8 2 4 9 11 3 10 5 12,这和我理解的也是一致的,请问你的第一个运行结果是在什么环境下的?

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题