3

So, it may be repeated. Pardon me for my ignorance. I just want to clarify things.

function Person(name) {
    this.name = name;
}

Now you do,

var eve = new Person("Eve");

So,

eve.__proto__ == Person.prototype

Returns true.

Makes sense.

eve.__proto__.__proto__ == Object.prototype

also makes sense true.

Why Person.__proto__ == Object.prototype returns false?

Every object prototypically inherits from Object right?

What am I missing?

Please clarify things with examples.

I am almost lost.

StrugglingCoder
  • 4,781
  • 16
  • 69
  • 103

1 Answers1

0

proto is the actual object that is used in the lookup chain to resolve methods, etc. prototype is the object that is used to build proto when you create an object with new:

( new Foo ).__proto__ === Foo.prototype
( new Foo ).prototype === undefined

From : __proto__ VS. prototype in JavaScript

Léo R.
  • 2,620
  • 1
  • 10
  • 22
  • 1
    Please do not copy answers but flag as a duplicate instead. – Adrien Brunelat Jan 12 '18 at 09:51
  • @Leo R. I Understand. But why in my example it returns false, I am not getting. – StrugglingCoder Jan 12 '18 at 09:51
  • @AdrienBrunelat I am still not clear. Could you explain why is it being closed? – StrugglingCoder Jan 12 '18 at 09:58
  • @StrugglingCoder, Default `__proto__` of objects is Object.prototype. However Person is a function and is linked to `Function.prototype`. `Person.__proto__ == Function.prototype` – FredG Jan 12 '18 at 10:00
  • @StrugglingCoder because this answer is an exact copy of the one in the duplicate and that all elements you need to answer your question are in this target post. – Adrien Brunelat Jan 12 '18 at 10:00
  • @AdrienBrunelat apparently, there are not. If you see clear connection between this answer to OP question point it instead of making non-constructive statements. – erhesto Jan 12 '18 at 10:03
  • @erhesto I don't understand anything of what you wrote. "there are not" doesn't mean anything and doesn't connect with anything, "connection between [...] to [...]" doesn't mean anything either. And I'm not even trying to link _this answer_ and _OP question_ – Adrien Brunelat Jan 12 '18 at 10:08
  • @AdrienBrunelat "and that all elements (...) are in this target post". <- that's not true, since OP is asking specific question that is not **directly** answered in this post. "connection between this answer **and** OP's question" is finally understandable? And you **are** linking this answer and question if you're saying that question is duplicate. – erhesto Jan 12 '18 at 10:17
  • I'm linking this answer with this one: https://stackoverflow.com/questions/9959727/proto-vs-prototype-in-javascript/9959753#9959753. Also I pointed that this question was _possibly_ a duplicate of the other one. I don't see where I have not been _constructive_. – Adrien Brunelat Jan 12 '18 at 10:19
  • Saying "all elements you need to answer your question are in this target post" isn't very constructive IMO, but okay, spending more time discussing constructiveness of answers isn't valuable at all. EOT. – erhesto Jan 12 '18 at 10:29