Javascript 如何对两个都返回承诺的函数的运行进行排序?
我的代码会检查word.statusId是否脏。如果是的话,它会更新word,如果是的话,它会更新wordForms。如果它是干净的,那么它只是更新wordForms。有人能告诉我,这是否是处理一个又一个承诺的正确方法吗Javascript 如何对两个都返回承诺的函数的运行进行排序?,javascript,typescript,Javascript,Typescript,我的代码会检查word.statusId是否脏。如果是的话,它会更新word,如果是的话,它会更新wordForms。如果它是干净的,那么它只是更新wordForms。有人能告诉我,这是否是处理一个又一个承诺的正确方法吗 update = (): ng.IPromise<any> => { var self = this; if (self.word.statusId != 3) { return self.wordEdi
update = (): ng.IPromise<any> => {
var self = this;
if (self.word.statusId != 3) {
return self.wordEditSubmit()
.then(() => {
return self.wordFormCheckAndUpdate();
})
} else {
return self.wordFormCheckAndUpdate();
}
}
update=():ng.IPromise=>{
var self=这个;
if(self.word.statusId!=3){
返回self.wordEditSubmit()
.然后(()=>{
返回self.wordFormCheckAndUpdate();
})
}否则{
返回self.wordFormCheckAndUpdate();
}
}
您所描述的期望行为实际上就是实际行为
在使用时,您不需要存储此的值:
update = (): ng.IPromise<any> => {
if (this.word.statusId != 3) {
return this.wordEditSubmit()
.then(() => this.wordFormCheckAndUpdate())
} else {
return this.wordFormCheckAndUpdate();
}
}
update=():ng.IPromise:
update=():ng.IPromise=>{
返回this.word.statusId!=3
?this.wordEditSubmit()。然后(()=>this.wordFormCheckAndUpdate())
:this.wordFormCheckAndUpdate();
}
update = (): ng.IPromise<any> => {
return this.word.statusId != 3
? this.wordEditSubmit().then(() => this.wordFormCheckAndUpdate())
: this.wordFormCheckAndUpdate();
}