Why is Object.prototype instanceof Object false?

匿名 (未验证) 提交于 2019-12-03 01:18:02

问题:

Why does the following return false?

Object.prototype instanceof Object 

回答1:

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.



回答2:

Referencing MDN:

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



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!