首页 > Object.getPrototypeOf(Object)和Object.prototype得到的结果为什么不一样?

Object.getPrototypeOf(Object)和Object.prototype得到的结果为什么不一样?

Object.getPrototypeOf(Object)
[Function: Empty]

Object.prototype
{}

两者都是获取Object的prototype,但为什么结果不一样呢?


呵呵呵呵你混淆了兩個概念。

The Object.getPrototypeOf() method returns the prototype (i.e. the value of the internal [[Prototype]] property) of the specified object.

The Function.prototype property represents the Function prototype object.
Function objects inherit from Function.prototype. Function.prototype cannot be modified.

Object.prototype === Object.getPrototypeOf(new Object());

Object 本身是一個 函數Object.prototype 不是 Object 這一對象的原型,而是 Obejct 這一函數的 函數原型,也就是 new Object() 的原型。

Object.getPrototypeOf(Object) 是把 Object 這一函數看作對象,返回的是 函數對象原型,也就是 Function.prototypefunction Empty() {} 了。

【热门文章】
【热门文章】