Lesson 23 of 55 · javascript
Prototype Chain & Inheritance
Duration: 10 mins
Every object has an internal [[Prototype]] (accessible via Object.getPrototypeOf).
const animal = { eats:true };
const rabbit = Object.create(animal);
rabbit.jumps = true;
console.log(rabbit.eats); // true – found on prototype
Prototype methods – Object.prototype.toString, Array.prototype.map.
Example: Adding a method to all objects
Object.prototype.log = function(){ console.log(this); };
({a:1}).log(); // {a:1}
(Use with caution – augmenting native prototypes can break libraries.)