标准代码:
(function() {
console.log(1);
window.setTimeout(() => {
console.log(2);
}, 100);
new Promise((resolve) => {
console.log(3);
resolve();
})
.then(() => {
console.log(4);
});
console.log(5);
})();
// 输出结果:
// - 1
// - 3
// - 5
// - 4
// - 2
在promise对象前添入 await 后:
(async function() {
console.log(1);
window.setTimeout(() => {
console.log(2);
}, 100);
await new Promise((resolve) => {
console.log(3);
resolve();
})
.then(() => {
console.log(4);
});
console.log(5);
})();
// 输出结果:
// - 1
// - 3
// - 4
// - 5
// - 2
标签:面试题,resolve,console,log,await,Promise From: https://www.cnblogs.com/fanqshun/p/17386388.html