简体   繁体   English

javascript Function.prototype问题

[英]javascript Function.prototype issue

I started learning JavaScript and have below question: 我开始学习JavaScript,并有以下问题:

 var f = function foo() {} Console.log(f.__proto__ === Function.prototype) //true Console.log(f.__proto__ instance of Function) //false 

Why 3rd statement using instanceof returns false. 为什么使用instanceof的第三条语句返回false。 My understanding is RHS of instance consults prototype of passed class and then match it in object or its proto. 我的理解是实例的RHS咨询通过的类的原型,然后将其匹配到对象或其原​​型中。 Please let me know what I am missing here? 请让我知道我在这里想念的吗? referred this for implementation of instance-of. 引用实例的实现。

referred this for implementation of instance-of 引用实例的实现

Well, that's simply a wrong implementation. 好吧,那只是一个错误的实现。 The instanceof operator does not match the object itself, only its prototypes, against the .prototype of the constructor. instanceof运算符不会将对象本身(仅是原型)与构造函数的.prototype相匹配。 Your 你的

x instanceof Function

is equivalent to 相当于

Function.prototype.isPrototypeOf(x)

which for f.__proto__ (ie Function.prototype ) does not hold - it is not the prototype of itself. 对于f.__proto__ (即Function.prototype )而言,这不成立-它不是其原型。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM