js中promise的嵌套问题

function s1() {
    return new Promise(function(resolve, reject) {
       console.log('函数s1执行')
       s2()
    })
}

function s2(){
    return new Promise(function(resolve, reject) {
        console.log('函数s2执行')
        resolve()
    })
}

s1().then(function(){
    console.log('函数s1的then语句')
})  

这样只能执行s1和s2,s1后边的then语句怎样才能执行

阅读 3.3k
4 个回答

s2()改成resolve(s2())

s1没有执行resolve

后面跟then,需要 thenable

s1的两个参数函数记得用啊…成功了就resolve([agrv]),失败了就reject([agrv])

reslove才会触发promise的成功状态。有上面两个参数函数运行才会触发promise的then

推荐问题