Why do we need pipe or compose?

In one of the previous articles, we discussed the need for chaining several functions, and how to do them using the this operator. While this works fine, there are several drawbacks to using this method:

  1. One has to keep track of this. And the value must be stored in the this operator so that the functions chained later on gets to access this value.
  2. The syntax is not quite intuitive. If there are many functions, it would look something like this -> functionA().functionB().functionC().functionD().......functionZ().

To reduce the effects of these two caveats, the implementation of pipe() and compose() functions can be used.

#javascript #frontend #javascript-tips #frontend-development

Javascript: Pipe and Compose Functions
2.25 GEEK