EcmaScript语法

时间:2018-10-02 10:53:36

标签: javascript ecmascript-6 promise

与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中完成

它有语法吗?

1 个答案:

答案 0 :(得分:1)

您还可以嵌套第二个“ then”以将第一个asyncResponse保留在作用域中

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