🔸prototype

🚧 under construction

JSvalueobject ⟩ prototype

desc

  • objects have a special hidden property [[Prototype]] that is either null or references another object (other types are ignored).

  • that object is called a “prototype”.

  • when we access an object's method/property, and it’s missing, JavaScript automatically takes it from the prototype.

__proto__

// ⭐️ `__proto__` is a getter & setter for [[Prototype]]
obj.__proto__            // call getter
obj.__proto__ = proto    // call setter
Object.getPrototypeOf(obj)
Object.setPrototypeOf(obj, proto)

prototype chain can't go in circles.

Last updated