js中Object.__proto__===Function.prototype
参考:http://stackoverflow.com/questions/650764/how-does-proto-differ-from-constructor-prototype
__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
The most surprising thing for me was discovering that Object.__proto__
points to Function.prototype
, instead of Object.prototype
, but I'm sure there's a good reason for that :-)
I think the class Object
itself is an instance of Function
, that's why Object.__proto__ === Function.prototype
.
The reason why Object.__proto__
points to Function.prototype
is because Object()
by itself is a native function that instantiates an empty object. Therefore, Object()
is a function. You'll find that all the other major native types' __proto__
properties point to Function.prototype
. Object
, Function
, String
, Number
, and Array
all inherit the Function prototype.
This means that adding to Function.prototype
will automatically reflect on all objects whose __proto__
is referencing the Function.prototype
.
For example, look the map below:
Furthermore, even the class Function
itself is an instance of Function
itself, that is Function.__proto__ === Function.prototype
, that's also why Function === Function.constructor
Further furthermore, the regular class Cat
is an instance of Function
, that is Cat.__proto__ === Function.prototype
.
The reason for the above is, when we create a class in JavaScript, actually, we are just creating a function, which should be an instance of Function
. Object
and Function
are just special, but they are still classes, while Cat
is a regular class.
As a matter of factor, in Google Chrome JavaScript engine, the following 4:
Function.prototype
Function.__proto__
Object.__proto__
Cat.__proto__
They are all ===
(absolutely equal) to the other 3, and their value is function Empty() {}
> Function.prototype
function Empty() {}
> Function.__proto__
function Empty() {}
> Object.__proto__
function Empty() {}
> Cat.__proto__
function Empty() {}
> Function.prototype === Function.__proto__
true
> Function.__proto__ === Object.__proto__
true
> Object.__proto__ === Cat.__proto__
true
prototype-chain
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!