Member-only story

JS Interview Questions (2)

Beck Moulton
6 min readAug 1, 2023

--

Nine, what is the prototype, prototype chain?

Prototype:

Each constructor function has a prototype property, that is, an explicit prototype property, which points to the prototype object of the constructor function

Each instance object has a __proto__ property, the implicit prototype property, which points to the prototype object that constructed the function

The value is set to the prototype object through the explicit prototype property, and the value is read to the prototype object through the implicit prototype property, that is, the implicit prototype property value of the instance object is equal to the explicit prototype property value of its constructor function

Prototype chain:

Each prototype object that constructs a function, which defaults to an empty Object instance object of the constructor function, also has a __proto__ property

A chain of __proto__ properties of instance objects and prototype objects, the prototype chain, ending with the __proto__ properties of the prototype object from which Object constructs function

When reading a value on an instance object, it is first found on the instance object itself, and when it cannot be found, it is found on the prototype object of its constructor function through the __proto__ property.

If you can’t find it yet, continue looking up the __proto__ property until Object constructs the __proto__ property…

--

--

Beck Moulton
Beck Moulton

Written by Beck Moulton

Focus on the back-end field, do actual combat technology sharing Buy me a Coffee if You Appreciate My Hard Work https://www.buymeacoffee.com/BeckMoulton

No responses yet