freecoding.school100% FREE · NO SIGNUP
Closure CavesISSUE #43 of 61

prototypes · the old inheritance

LambdaVSThe Mutator
Lambda saysPrototypes are the real inheritance mechanism classes are built on.

Every object has a hidden link (__proto__) to a prototype object; property lookups walk this prototype chain until found or null. Classes just configure prototypes for you. Understanding this explains why all array instances share map (it lives on Array.prototype) and why you can extend built-ins (carefully).

Power-ups you unlock

The Mutator attacks — common mistakes

Boss battleShow that an array instance finds map() on Array.prototype.

Example code

<!doctype html><html><head><meta charset="utf-8"></head>
<body style="background:#06040d;color:#e6e0ff;font-family:monospace;padding:20px"><pre id="o"></pre>
<script>const a=[1,2];
document.getElementById('o').textContent='map on prototype: '+(Object.getPrototypeOf(a)===Array.prototype);</script></body></html>
▶ Open the interactive comic issue
‹ Classes · Static · Private · #FieldsSymbols · Unique Keys ›