mut*_*ity 2 javascript promise q bluebird
继承我的代码:
var delete_card = function(){
stripe.customers.deleteCard(
this.service_id.stripe,
this.credit_card[0].stripe_id
)
.then(function(obj){
this.recipients.splice(0, 1);
return this.save()
})
}
Run Code Online (Sandbox Code Playgroud)
条带调用和保存调用都返回promise.
我如何从delete_card方法返回一个promise?
我会像新的Promise一样包装它们并从那里返回一个承诺吗?
我将如何构建,以便将错误和结果冒出来?
我希望能够像这样从调用者那里做一些事情:
delete_card
.then(...)
.catch(...)
Run Code Online (Sandbox Code Playgroud)
并继续撰写链式承诺?
只需返回delete_card
函数中的promise即可.
var delete_card = function(){
/************/
/**/return/**/ stripe.customers.deleteCard(
/************/
this.service_id.stripe,
this.credit_card[0].stripe_id
)
.then(function(obj){
this.recipients.splice(0, 1);
return this.save()
})
}
Run Code Online (Sandbox Code Playgroud)
编辑:return
由于代码差异如此微妙,我明白了哪里添加了令人讨厌的东西.
归档时间: |
|
查看次数: |
73 次 |
最近记录: |