Lesson 30 / 38
Prototypes
The mechanism classes are built on.
The prototype chain
Every object has an internal link to a prototype object it falls back to for properties or methods it doesn't have directly.
Prototype in action
Object.create builds an object whose prototype is explicitly set to another object.
const animal = { eats: true };
const rabbit = Object.create(animal);
console.log(rabbit.eats); // true, inherited
console.log(rabbit.hasOwnProperty("eats")); // falseA chain of fallbacks
Think of the prototype chain like asking a parent, then grandparent for something you don't have — JS keeps climbing until it finds the property or hits null.