liveBook · Manning

Partial application

As explained in The Joy of JavaScript

Partial application is the creation of a new function by binding some arguments of an existing function while leaving the remaining arguments to be supplied later.

Partial application creates a new function by binding some arguments while leaving the remaining arguments for later. In JavaScript, manual currying makes this pattern explicit and composable. section 4.4.1

Bind one argument

Define add as x => y => x + y, bind x with add(3), then call addThreeTo(7) to produce 10. The bound value remains in the returned function’s closure.

Configure a pipeline step

Define decode as an encoding-taking function that returns a buffer decoder. Using decode('utf8') makes the encoding visible while leaving the buffer for the composition pipeline.

Create reusable accessors

Bind prop’s name parameter with prop('funds), producing getFunds or fundsOf for extracting funds from different transaction objects and collections.

How The Joy of JavaScript covers it

How deep it goes
Explains manual currying, closures, automated currying, and arity-sensitive edge cases such as default parameters.
Examples
Uses addition, buffer decoding, word counting, transaction property access, multi-property extraction, and mapped collection accessors.
What it assumes
Assumes JavaScript functions, closures, arrow functions, higher-order functions, and array mapping.
What you can do after
Build reusable JavaScript functions by binding configuration now and supplying operational data later.
How it connects
Connects partial application with currying, closures, higher-order functions, composition, mapping, and declarative programming.

Also explained in

Compare how 10 books explain partial application →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of The Joy of JavaScript. The section links point to the parts of the book it draws on.