javascript - Why is Object.__proto__.__proto__ not null? - Stack Overflow

My understanding is that the Object.__proto__ is the 'top-level' prototype object in javascri

My understanding is that the Object.__proto__ is the 'top-level' prototype object in javascript. I would expect its __proto__ to be null, but in Google Chrome (haven't tried other browsers), it isn't. Why is that?

Edit

I know the following image is probably a re-hash of the one below, but I made it myself to check my understanding. Is there anything wrong with it?

My understanding is that the Object.__proto__ is the 'top-level' prototype object in javascript. I would expect its __proto__ to be null, but in Google Chrome (haven't tried other browsers), it isn't. Why is that?

Edit

I know the following image is probably a re-hash of the one below, but I made it myself to check my understanding. Is there anything wrong with it?

Share Improve this question edited Dec 28, 2018 at 5:14 Cœur 38.8k25 gold badges205 silver badges277 bronze badges asked Jul 29, 2015 at 16:52 jmrahjmrah 6,2695 gold badges32 silver badges43 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 6

Object is a function, it's __proto__ is an empty function function() {}. The root object is an empty object {}, not Object. So, when you have an object like {foo:1, bar:1} its relationships look like this:

I think you're mistaking Object.__proto__ for Object.prototype.

Object.prototype.__proto__ is indeed null, because Object doesn't extend anything.

Object itself, however, is a function - aka. an instance of Function.
Since Function extends Object, it's prototype has a __proto__ property.
You can thus take a detour over Object.__proto__.__proto__ to reach Object.prototype, in fact:

Object.prototype === Object.__proto__.__proto__ // should yield true

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744131164a4559848.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信