2016-12-27 54 views
6

我在使用.then函数和_.bind函数。我想停止函数的执行,(即)前一个函数的输出是为下一个函数输入的。这是我的代码。返回false不工作,然后用lodash绑定函数

return getProducts(barcode, sku) 
.then(_.bind(this.checkForPrice, this)) 
.then(_.bind(this.addLinkedProducts, this)) 
.then(null, _.bind(this.handleUnknownError, this)); 

checkForPrice功能,我使用返回false就停止执行下面的一样,但它并没有停止流动。

checkForPrice: function (products) { 
       debugger; 
       if (!products) { 
        return false; 
       } 

       return something; 
} 

请帮助解决此问题。

+0

“停止执行”是什么意思?你有没有尝试抛出一个错误? – thefourtheye

+0

@thefourtheye。我想停止下一个功能。我没有试图抛出错误 – Jegan

+0

返回一个值将简单地落在链中,然后转到下一个处理程序。请尝试抛出一个错误。 – thefourtheye

回答

0

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