๐Ÿ”ธprototype

๐Ÿšง under construction

JS โŸฉ value โŸฉ object โŸฉ 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

Was this helpful?