以上步驟重複執行就是事件輪詢promise
setTimeout(function () { console.log('setTimeout'); }) new Promise(function (resolve) { console.log('promise'); }).then(function () { console.log('then'); }) console.log('console');
function aaa() { console.log(123) } setTimeout(function () { console.log('setTimeout'); }); (() => new Promise(function (resolve) { console.log('promise'); resolve(aaa()) }).then(function () { console.log('then'); }))(); console.log('console');
async function async1() { console.log("async1 start") await async2() console.log("async1 end") } async function async2() { console.log("async2") } console.log("script script") setTimeout(function () { console.log("setTimeout") }, 0) new Promise(function (resolve) { console.log("promise1") resolve() }).then(function () { console.log('promise2') }) async1() console.log("script end")
console.log('example-start') setTimeout(() => { console.log('setTimeout-0') }, 0) new Promise((resolve, reject) => { console.log('promise-1') resolve('promise-2') Promise.resolve().then(() => console.log('promise-3')) }).then((response) => { console.log(response) setTimeout(() => { console.log('setTimeout-10') }, 10) }) console.log('example-end')