其他分享
首页 > 其他分享> > js事件循环

js事件循环

作者:互联网

async function async1() {
    console.log("a");
    const res = await async2();
    console.log("b");
}

async function async2() {
    console.log("c");
    return 2;
}

console.log("d");

setTimeout(() => {
    console.log("e");
}, 0);

async1().then(res => {
    console.log("f")
})

new Promise((resolve) => {
    console.log("g");
    resolve();
}).then(() => {
    console.log("h");
});

console.log("i");

/**
* 输出结果:d a c g i b h f e 
*/
console.log("a");

setTimeout(function () {
    console.log("b");
}, 0);

new Promise((resolve) => {
    console.log("c");
    resolve();
})
    .then(function () {
        console.log("d");
    })
    .then(function () {
        console.log("e");
    });

console.log("f");

/**
* 输出结果:a c f d e b
*/

 

from:https://mp.weixin.qq.com/s/ymla1LAP2LRHXyO9iKZWVA

标签:function,async2,resolve,console,log,res,js,循环,事件
来源: https://www.cnblogs.com/liuqiyun/p/15623456.html