1

(__proto__ property refers to the actual prototype of an object.)

Object is a function (and also used as a constructor).

Since it is a function, it's constructor should be Function.

So, if I wanted some property added to Object, I could add it to Function.prototype.

But, Function is an object and all objects inherit from Object in some way.

Is this actually a cyclic relation?

I read this in an MDN page :

(some function) ---> Function.prototype ---> Object.prototype ---> null

How can null be the __proto__ of Object? Isn't it Function.prototype again?

batman
  • 5,022
  • 11
  • 52
  • 82
  • 1
    Take a look at this answer: http://stackoverflow.com/questions/650764/how-does-proto-differ-from-constructor-prototype. – Andries Dec 13 '12 at 10:35

2 Answers2

0

After reading up on this, I think the diagram in this answer, answers the question.

Every object in Javascript is has a __proto__ property which is the same as it's constructor's prototype property. So, if a property of an object isn't found, it looks it up in it's __proto__ property and upwards like that, until it either finds it or reaches null.

Object.prototype is THE end of the prototype chain, with Object.prototype.constructor being Object.

The fact that Object is a function, would mean that, Object.__proto__ is Function.prototype(because Object could have been created as new Function())

but not that Object.prototype.__proto__ is Function.prototype.

So, the __proto__ chain goes Function.prototype --> Object.prototype --> null

I hope I got it right.

Community
  • 1
  • 1
batman
  • 5,022
  • 11
  • 52
  • 82
-1

If I understand correctly, Function and Object hold the top positions together. Since Function has an Object as it's prototype, and Object, as a constructor, is actually a Function.

This sort of mutual dependency/inheritance is common on fully OO languages, and can become much more complicated that this (rather simple) two-item version. Take a look at Ruby's inheritance diagram (in beautiful ascii art!) to see how brain-wrenching it can be :)

The good thing is, you usually don't have to worry about it. It should Just Work™.

marcus erronius
  • 3,613
  • 1
  • 16
  • 32