liveBook · Manning

Function binding

Function binding is the creation of a function with a predetermined this value and, optionally, preset arguments.

How 2 Manning books explain it

Functional Programming in JavaScript

The technique of associating a function with a specific this value or preset arguments so it can be invoked in a controlled context.

How it is used
Uses preset arguments to turn general functions into modular, reusable operations.
How deep it goes
Defines binding, contrasts it with currying and partial application, and demonstrates configured callbacks without detailing binding internals.
Examples
Demonstrates a bound logger, partially configured string methods, and scheduled callbacks.
What you can do after
Apply it via Lodash _.bind or JavaScript Function.prototype.bind to create configured functions.

Read how Functional Programming in JavaScript explains function binding →

The Joy of JavaScript

The JavaScript method that creates a new function with a bound this value and optional leading arguments.

How it is used
Uses bind to repair a method's this reference while composing functions around object state.
How deep it goes
Explains context correction, partial argument application, and maintainability tradeoffs before shifting to explicit parameters.
Examples
Uses assemble.bind(this, keys) inside calculateHash and contrasts it with assemble(keys, obj).
What you can do after
Apply it via JavaScript's bind method to preserve object context and prefill keys, while recognizing its maintainability cost.

Read how The Joy of JavaScript explains function binding →

Related concepts

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.