Chapter XIX · Prototypes
Prototype
A prototype is an underlying object linkage from which other objects inherit properties and methods.
01 How It Works
Think of an original master template design sheet that blueprint copies reference for shared features.
Every JavaScript object has an internal link (`[[Prototype]]`) pointing to another object, forming the foundation of prototype-based inheritance.
example.js
const obj = {};
console.log(obj.__proto__); // Object.prototype
1. Create an object or constructor function.
2. Access its internal prototype link via `__proto__` or `Object.getPrototypeOf()`.
3. Share properties and methods dynamically across linked structures.
02 Practical Example
Here is how you might see this concept applied in real-world code:
practical.js
const animal = { eats: true };
const rabbit = Object.create(animal);
console.log(rabbit.eats); // true (inherited via prototype)
Key Takeaway
Prototypes enable efficient property and method sharing across objects without duplicating memory.