Prototypes and Prototype Chains
- Prototypes. Every object holds a hidden link to another object: its prototype: where property lookup continues when the object lacks a name.
- The prototype chain. Lookups climb link by link up the chain until the property is found or the chain ends at null.
- Shared methods. Array methods like push live once on Array.prototype and are shared by every array through that chain.
Classes and Object-Oriented JavaScript
- Classes. A class is JavaScript’s clean syntax for building objects from a blueprint: underneath it still wires prototypes.
- Constructors. The constructor method runs once per new instance, receiving arguments and setting up that object’s own properties.
- Inheritance. The extends keyword chains one class’s prototype to another’s, so a subclass reuses and overrides behaviour.
Composition and Encapsulation
- Encapsulation. Encapsulation hides an object’s internals: with #private fields or closures: so outside code touches only the intended surface.
- Composition. Composition builds behaviour by combining small objects and functions, and usually bends better than deep inheritance trees.
- Choosing a design. Prefer composition when behaviours mix and match; reach for inheritance only when one thing truly is a kind of another.
Before and after this level
- Before: Level 5: JavaScript's Type System: Primitive and Reference Values, Coercion, Equality and Truthiness, Understanding null, undefined and Special Values.
- Next: Level 7: Modules & Code Organisation: ES Modules, Imports, Exports and Dependencies, Designing Maintainable Modules.
In the app each of these ideas is taught and then asked back, and the level ends with a checkpoint and flashcards. See Checkpoints and flashcards.
Frequently asked questions
What does JavaScript Level 6: Objects & Prototypes cover?
Prototypes and Prototype Chains, Classes and Object-Oriented JavaScript, Composition and Encapsulation: 3 lessons and 9 ideas.
What should I know before this level?
The level before it, Level 5: JavaScript's Type System, which covers Primitive and Reference Values, Coercion, Equality and Truthiness, Understanding null, undefined and Special Values.