Tip 35 Combine Currying and Array Methods for Partial Application

In this tip, you’ll learn to lock in variables with partial application of functions.

In the previous tip, you saw how you can give parameters a single responsibility with higher-order functions and partial application. It solved the problem of having unrelated parameters, but it didn’t solve the problem of using the same parameters over and over. You still passed in the same parameters multiple times.

With higher-order functions, you can avoid repetition by creating a new function with values you lock in once and use later. When you return a higher-order function, you don’t have to invoke it right away. After you invoke it once, you have another pre-made function that ...

Get Simplifying JavaScript now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.