🔰prototype chain
JS ⟩ value ⟩ object ⟩ prototype ⟩ chain
the linked series of prototype objects of an object is called it's prototype chain.

- prototype chain can't go in circles. 
- function's prototype (property) - new instances' prototype/parent object. 
- object's property - object's parent in prototype chain. 
- printPrototypeChain() - print the prototype chain of an object. 
- "obj instanceof A" checks if - A.prototypeis in the prototype chain of- obj.
- function's prototype is used in prototype chain. 
- method uses [[HomeObject]]'s prototype to trace super. 
- replit ⟩ class B extends A 
const { log } = console;
// ---------------------- main ------------------------------------
class A {}
class B extends A {};
let a = new A();
let b = new B();
// b's prototype chain
const b1 = b.__proto__;        // B.prototype
const b2 = b1.__proto__;       // A.prototype
const b3 = b2.__proto__;       // Object.prototype
const b4 = b3.__proto__;       // null
// B's prototype chain
const B1 = B.__proto__;
const B2 = B1.__proto__;
const B3 = B2.__proto__;
const B4 = B3.__proto__;
// ---------------------- console ----------------------------------
[
    // b's prototype chain
    b1 === B.prototype,        // true: b is a `B`
    b2 === A.prototype,        // true
    b3 === Object.prototype,   // true
    b4 === null,               // true
    
    B1 === A,                   // true: B inherits from A
    B2 === Function.prototype,  // true: A is a `function`.
    B3 === Object.prototype,    // true: `Function.prototype` is an `Object`.
    B4 === null,                // true: `Object.prototype` inherits from nothing.
    
].forEach(x => log(x));- ObjectPlayground - visualize prototype chain (cool ⭐️) 
Last updated
Was this helpful?