🧬

Prototype Chain — Inheritance Before class Existed

The relationship between __proto__, prototype, and Object.create()

proto vs prototype

__proto__ — internal link every object has. Points to the object's "parent." (Official: [[Prototype]])

prototype — property only functions have. Objects created with new Foo() get their __proto__ pointed at Foo.prototype.

class Is Syntactic Sugar

Whether you use class or function, the prototype chain is identical. class didn't create a new inheritance model — it wrapped the existing prototype chain for readability.

Property Lookup Order

obj.prop: obj itself → obj.proto → ... → null. If null reached, returns undefined.

Key Points

1

Every object references parent via __proto__ (=[[Prototype]])

2

new Foo() objects have __proto__ pointing to Foo.prototype

3

Property lookup: self → __proto__ → __proto__.__proto__ → null

4

class is syntactic sugar for prototype-based inheritance — same internals

Use Cases

Reading library code — must understand prototype manipulation Polyfill implementation — adding methods to Array.prototype