我在一系列中使用 .then
函数和 _.bind
函数。我想停止函数执行,(即前一个函数的输出是下一个函数的输入)。这是我的代码。
return getProducts(barcode, sku)
.then(_.bind(this.checkForPrice, this))
.then(_.bind(this.addLinkedProducts, this))
.then(null, _.bind(this.handleUnknownError, this));
在 checkForPrice
函数中,我使用 return false 来停止执行,如下所示,但它并没有停止流程。
checkForPrice: function (products) {
debugger;
if (!products) {
return false;
}
return something;
}
请帮助解决此问题。
最佳答案
根据 @thefourtheye 的评论,如果我抛出一个错误,它就会停止链。
关于javascript - return false 在 then 中不起作用,并且使用 lodash 绑定(bind)函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41341182/