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结果

Promise与setTimeout,观察js执行顺序

 

上一篇:JS延迟处理方法


下一篇:for循环+setTimeout()引发变量作用域问题