undefinedfix
Sign in

Promise.resolve Why not call the following then when the parameter of is thenable?

qslnl edited in Tue, 14 Jun 2022
Promise.resolve()
.then( value => {
    console.log(0);
    return Promise.resolve({
        then() {
            console.log(1);
        }
    })
})
.then( value => {
    
    return Promise.resolve({
        then() {
           console.log(2);
        }
    })
})
.catch(()=>{
   console.log('not yet');
}) 
2 Replies
jakab922
commented on Tue, 14 Jun 2022

MDN problem thenablethenable is used in this way

Promise.resolve({
  then(resolve) {
    console.log(1);
    resolve(2)
  }
}).then(v=>{
  console.log(v) //2
})
cstlr
commented on Tue, 14 Jun 2022

Thenable mainly ensures that all kinds of promise / A + implementations can be mixed. Generally, it can't be used. When using promise, just remember to have such a thing

lock This question has been locked and the reply function has been disabled.