intermediate · 23 minute study
Method calls choose a receiver
Passing an object method as a callback can lose its receiver. Understanding prototypes also makes classes less mysterious.
Useful preparation · 1 prerequisite
Use this as a map, not a lock. If these ideas are familiar, continue.
- A closure keeps access to its lexical environment — Closures power callbacks and private state, but also explain stale values, memory retention and confusing loop behavior.
First, build a mental model
For an ordinary function, this depends on how it is called. Objects delegate missing property lookups along a prototype chain. Class syntax organizes that model; it does not replace it.
- player.label() supplies player as the receiver.
- Extracting a method into a variable does not preserve the receiver.
- bind returns a function with a fixed this; an arrow captures lexical this.
- Prototype methods can be shared by instances instead of allocating the same function on each one.
'use strict';
const player = { name: 'Mira', label() { return this.name; } };
const detached = player.label;
console.log(player.label());
try { console.log(detached()); } catch (error) { console.log(error.name); }
const bound = player.label.bind(player);
console.log(bound());- Method call
player is the receiver, so this.name is Mira.
- Detached call
No object receiver is supplied. Strict mode gives undefined this.
- Bound call
bind supplies player regardless of the later call site's receiver.
Production thinking
Take this beyond the example.
Use composition and plain functions when they make ownership clearer. Choose classes for useful state/behavior contracts, and be explicit at callback boundaries.
Sources and further reading
Your evidence
unseen is a local learning signal, not a credential or proof of production competence.
Explain the mental model, then explicitly acknowledge it. Opening a page is not evidence.
Supported retries can complete this lesson. Independent evidence and delayed review determine the skill stage.
Next lesson · One event travels through a tree →