- 首页 > it技术 > >
如果你搞明白了为什么输出这个结果那么js的事件执行机制才算明白了
console.log('1');
setTimeout(function () {
console.log('2');
new Promise(function (resolve) {
console.log('3');
resolve();
}).then(function () {
console.log('4')
})
},0)new Promise(function (resolve) {
console.log('5');
resolve();
}).then(function () {
console.log('6')
})setTimeout(function () {
console.log('7');
new Promise(function (resolve) {
console.log('8');
resolve();
}).then(function () {
console.log('9')
})
console.log('10')
},0)console.log('11')
//输出结果:15 11 6 2 34 7 810 9
推荐阅读