【发布时间】:2017-05-11 12:07:16
【问题描述】:
我在一系列中使用.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。我想停止下一个功能。我没有尝试抛出错误
-
返回一个值将简单地落下链条并转到下一个 then 处理程序。请尝试抛出错误。
-
@thefourtheye 。让我试试看。
-
@thefourtheye。它正在工作。如果我抛出一个错误,它会停止链条。谢谢。
标签: javascript lodash