返回博主主页

Promise与setTimeout,观察js执行顺序

1代码示例

new Promise(function(resolve, reject) {
    console.log(1);
    setTimeout(function() {
        console.log("First");
        resolve();
    }, 1000);
    console.log(2);

}
).then(function() {
    console.log(3);

    return new Promise(function(resolve, reject) {
        setTimeout(function() {
            console.log("Second");
            resolve();
        }, 4000);
    }
    );
}).then(function() {
    console.log(4);

    setTimeout(function() {
        console.log("Third");
    }, 3000);
    console.log(5);

});
console.log(0)

2结果

 

posted @ 2022-01-12 14:50  懒惰的星期六  阅读(49)  评论(0编辑  收藏  举报

Welcome to here

主页