【问题标题】:return false is not working in then and bind function with lodashreturn false 在 then 中不起作用并使用 lodash 绑定函数
【发布时间】: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


【解决方案1】:

根据@thefourtheye 的评论,如果我抛出错误,它将停止链。

【讨论】:

    猜你喜欢
    • 2014-01-12
    • 2021-08-19
    • 2018-02-13
    • 2014-08-09
    • 2020-02-08
    • 1970-01-01
    • 1970-01-01
    • 2021-06-13
    • 2021-11-03
    相关资源
    最近更新 更多