🔰prototype chain
JS ⟩ value ⟩ object ⟩ prototype ⟩ chain
the linked series of prototype objects of an object is called it's prototype chain.
從下圖可看出 base class 與 derived class 的連結(繼承)方式,其實是不一樣的:
身為使用者自創的第一個 class,base class A 與 A.prototype 所連接的分別是 Function.prototype 與 Object.prototype。
derived class B 與 B.prototype 則分別連接 A 與 A.prototype。

prototype chain can't go in circles.
the assignment of a property (dot/bracket notation) always creates/sets a property in the original object, it never modifies objects in the prototype chain.
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 ofobj.function's prototype is used in prototype chain.
method uses [[HomeObject]]'s prototype to trace super.
replit ⟩ class B extends A
ObjectPlayground - visualize prototype chain (cool ⭐️)
Last updated