Javascript instanceof 奇怪的行为

Javascript instanceof weird behavior

为什么 returns 是假的?

function f(){ return f; }
new f() instanceof f; // Prints false instead of true 

据我了解,在这种特殊情况下 instanceof 应该检查如下内容:

newObj.__proto__ === f.prototype

并且 newObj.__proto__ 应该在 new f() 调用时自动设置。

构造函数隐式 return thisthis 构造函数的实例,因此,如果您 return this 该函数的计算结果为真。

不是returnthis。你 return f 不是构造函数的实例,因此表达式 returns false.