问题描述
在Google Chrom的javascript中,对象具有名为__proto__
的属性,该属性指向其原型(或父对象)对象.
In Google Chrom's javascript, objects have a property named __proto__
that points to their prototype (or parent) object.
var foo = {};
console.log(foo.__proto__ === Object.prototype); //returns true
但是,对于Object
对象,这不正确.
However, this is not true for the Object
object.
console.log(Object.__proto__ === Object.prototype); //returns false
Object.__proto__
属性似乎是一个空方法
The Object.__proto__
property appears to be an empty method
> console.log(Object.__proto__.toString());
function () {}
除了作为警告故事,还依赖于从标准主体开始的javascript功能-Object.__proto__
函数是什么?
Beyond serving as a warning story about relying on javascript features that start outside standard bodies -- what is the Object.__proto__
function?
推荐答案
基于上面的斜眼的注释,我已经能够深入了解这一点.我未声明的,不正确的(并且是10年以上的)假设是,全局Object
辅助对象的原型对象也是javascript原型链顶部/末端的顶级原型原型".这不是真的.
Based on squint's comments above, I've been able to get to the bottom of this. My unstated, incorrect (and 10+ year) assumption was that the global Object
helper object's prototype object was also the top level "prototype of prototypes" at the top/end of javascript's prototype chain. This is not true.
Object
辅助对象和Function
辅助对象都具有相同的父原型对象
The Object
helper object and the Function
helper object both have the same parent prototype-object
console.log( Object.__proto__ === Function.__proto__ ); //true
因此,Object.__proto__
指向空函数的原因是-空函数是Object
对象的原型对象.如果要从Object
获取原型的原型(不使用.prototype
),则需要进一步追溯.
So, the reason Object.__proto__
points to an empty function is -- that empty function is its prototype object for the Object
object. If you want to get to the prototype of prototypes from Object
(without using .prototype
), you need to dig back a bit further.
console.log( Object.__proto__.__proto__ === Object.prototype ); //true
我还整理了一个快速图表,该图表绘制了Javascript的一些较低级别的辅助对象/构造函数对象的真实原型.
I also put together a quick diagram that maps out the real prototypes of a few of Javascript's lower level helper/constructor objects.
最后-我还发现Google Chrome浏览器实现了Reflect
对象其中包含一个getPrototypeOf
方法,该外观似乎与Object.getPrototypeOf
方法相同.
Finally -- I also also discovered Google Chrome has implemented the Reflect
object, which includes a getPrototypeOf
method, which appears to be the same as the Object.getPrototypeOf
method.
这篇关于Object .__ proto__中包含什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!