Why is Object.prototype instanceof Object false?

2019-01-20 08:50发布

Why does the following return false?

Object.prototype instanceof Object

2条回答
Emotional °昔
2楼-- · 2019-01-20 09:16

Referencing MDN:

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

查看更多
3楼-- · 2019-01-20 09:31

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.

查看更多
登录 后发表回答