0

Question related to EcmaScript:

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

The problem is: How to pass to the to the _thirdMethod 2 arguments (one from this._secondMethod(asyncResponse)) - that gives one argument and second is just previous asyncResponse) - I don’t want to define it inside _secondMethod(asyncResponse) to return these two arguments, just want to do it in this PIPE that I wrote above

Is there any syntax for it?

Yashwardhan Pauranik
  • 5,370
  • 5
  • 42
  • 65
emka26
  • 433
  • 1
  • 11
  • 28

1 Answers1

1

You can also nest the second "then" to keep the first asyncResponse in the scope

this._myFunction(firstArg)
    .then((asyncResponse) => this._secondMethod(asyncResponse)
    .then((asyncSecondResponse) => this._thirdMethod(asyncSecondResponse, asyncResponse)))
    .then(() => this._lastMethod());
  }
Mumrah81
  • 2,034
  • 2
  • 16
  • 23