0

Imagine simple function:

function Person();

I know that Person has __proto__ property that references to Function.prototype.

I also know that Person has prototype property. When I write: function Person() {}, a new prototype object is automatically created:

Person.prototype = { constructor: Person };

but inside Person.prototype block, I also have __proto__, so what is this __proto__, when is it created, who creates it?

I may know that it's Object's prototype but is it always so?

3
  • All constructors have prototype chains that drill down to Function.prototype, and all instances of objects created by these constructors have prototype chains that drill down to Object.prototype. Commented Jul 12, 2019 at 18:41
  • developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/… Commented Jan 19, 2021 at 13:03
  • Also, __proto__ is a pseudo-property (technically a getter/setter on Object.prototype) exposing the internal [[Prototype]] object. So even {} (an "empty" object) has a __proto__ property... Commented Jan 19, 2021 at 13:04

1 Answer 1

1

I'm not sure if I understand what you mean, but prototypes have their prototypes which can have their prototypes which can have their prototypes and so on until null. Based on your question you may know it's called prototype chain, if not now you know :) You can read in more detail about it on Mozilla docs.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.