promise多个then,如何不使用catch跳出中间的then
发布于 6 年前 作者 helloHT 4335 次预览 最后一次回复是 6 年前 来自 问答
function fun(callback){ Promise.then() .then(() => {}) .then(() => {}) .then(() => {callback()}) .then(() => {}) .then(() => {}) } 一个回调函数包含着一个promise,我想执行到callback就结束,而不执行后面的then,请问有什么优雅的写法么?
3 回复
function fun(callback){ Promise.then() .then(() => {}) .then(() => {}) .then(() => { callback(); return Promise.reject(); }) .then(() => {}) .then(() => {}) }
这样可以么?
可以
这样,也许是个方案