Partial application with eval()

If we want to be able to do partial application fixing of any combination of parameters, we must have a way to specify which arguments are to be left free and which will be fixed from that point on. Some libraries, such as Underscore or Lodash, use a special object, _ , to signify an omitted parameter. In this fashion, still using the same nonsense() function, we would write the following:

const fix2and5 = _.partial(nonsense, _, 22, _, _, 1960);

We could do the same sort of thing by having a global variable that would represent a pending, not yet fixed argument, but let's make it simpler, and just write undefined to represent a missing parameter.

When checking for undefined, remember to always use the ===

Get Mastering JavaScript Functional Programming - Second Edition 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.