This question already has answers here:
How do I access previous promise results in a .then() chain?
                            
                                (17个答案)
                            
                    
                2年前关闭。
        

    

与EcmaScript有关的问题:

const firstArg = 'myArg';
this._myFunction(firstArg)
  .then((asyncResponse) => this._secondMethod(asyncResponse))
  .then((asyncSecondResponse, asyncResponse) =>
   this._thirdMethod(asyncSecondResponse, asyncResponse))
  .then(() => this._lastMethod());


问题是:
如何传递给_thirdMethod 2个参数(this._secondMethod(asyncResponse))中的一个-提供一个参数,第二个只是先前的asyncResponse)-我不想在_secondMethod(asyncResponse)中定义它以返回这两个参数参数,只想在我上面编写的此PIPE中执行

有什么语法吗?

最佳答案

您还可以嵌套第二个“ then”以将第一个asyncResponse保留在范围内

this._myFunction(firstArg)
    .then((asyncResponse) => this._secondMethod(asyncResponse)
    .then((asyncSecondResponse) => this._thirdMethod(asyncSecondResponse, asyncResponse)))
    .then(() => this._lastMethod());
  }

07-24 20:14