Concepts

Object composition

Try the free JavaScript compiler

Design technique assembling behavior through collaborators rather than requiring a subtype hierarchy. Explicit ownership and contracts remain necessary.

Formal Syntax & Structure

javascript syntaxjavascript
function create(collaborator) { return { run() { return collaborator.run(); } }; }

Working Example

Example Snippetjavascript
function make(worker){return {run(){return worker.run();}};}console.log(make({run:()=>7}).run());
JavaScript Reference