在下面的代码块中,只有“first promise”被记录到控制台。这是为什么?我试图编写一个测试来弄清楚 .then() 在 .catch() 之后是如何执行的,但当除了第一个 promise 之外什么都没有运行时,我感到很惊讶。这是怎么回事?
function foo() {
return new Promise((resolve, reject) => {
return console.log('first promise')
})
.then(() => console.log('first then'))
.catch(() => console.log('catch block'))
.then(() => console.log('last block'))
.then(() => resolve)
}
foo();
最佳答案
正如 Yury 所说,您不是在解决 promise ,只是返回日志。
https://jsfiddle.net/k7gL57t3/
function foo() {
var p1 = new Promise((resolve, reject) => {
resolve("Test");
})
p1.then(() => console.log('first then'))
.then(() => console.log('last block'))
.then(() => resolve)
.catch(() => console.log('catch block'));
}
foo();
关于javascript - Promise.then 不执行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43896030/