liveBook · Manning

Mixin

As explained in Functional Programming in JavaScript

A reusable unit of behavior that can be composed into another type or object without classical inheritance.

A mixin is an object containing a related subset of functions that another object borrows to extend its behavior. It supports code reuse without classical inheritance and can model multiple-inheritance-like composition in JavaScript. section 3.4

Adding SQL-like operations to Lodash

Lodash can mix in aliases for familiar query operations, then chain them over data: _.mixin({'select': _.map, 'from': _.chain, 'where': _.filter, 'sortBy': _.sortByOrder}); The resulting API supports expressions such as _.from(persons).where(...).sortBy(['firstname']).select(...).value().

How Functional Programming in JavaScript covers it

How deep it goes
Defines the composition pattern and demonstrates one Lodash application, while deferring broader mixin coverage.
Examples
Uses Lodash aliases for select, from, where, and sortBy to build a chained SQL-like query.
What you can do after
Apply it via Lodash to add reusable, chainable operations without modifying inheritance relationships.
How it connects
Connects mixins with functional programming, method chaining, inheritance, multiple inheritance, traits, and SQL query languages.

Also explained in

Compare how 4 books explain mixin →

Related concepts

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