search

Home  >  Q&A  >  body text

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

Object.getPrototypeOf(Object)
[Function: Empty]

Object.prototype
{}

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

PHPzPHPz2896 days ago579

reply all(1)I'll reply

  • PHPz

    PHPz2017-04-10 14:41:42

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

    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() {} 了。

    reply
    0
  • Cancelreply