Why is Object.prototype instanceof Object false?

前端 未结 2 1073
既然无缘
既然无缘 2020-12-11 16:39

Why does the following return false?

Object.prototype instanceof Object
相关标签:
2条回答
  • 2020-12-11 17:16

    Because it basically asks whether Object.prototype does inherit from Object's .prototype object: It does not.

    a instanceof b is equivalent to b.prototype.isPrototypeOf(a) - it tests whether b.prototype is in the prototype chain of a. In your case, it is not in the chain, because it is the start of the chain itself. isPrototypeOf is not reflexive.

    0 讨论(0)
  • 2020-12-11 17:42

    Referencing MDN:

    The instanceof operator tests whether an object has in its prototype chain the prototype property of a constructor.

    0 讨论(0)
提交回复
热议问题