在JavaScript中,函数对象的原型是什么?

5
我刚刚写了这段代码。
 function Point(x,y){
        this.x = x;
        this.y = y;
    }
    var myPoint = new Point(4,5);
    console.log(myPoint.__proto__ === Point.prototype);
    console.log(Point.__proto__ === Function.prototype);
    console.log(Function.__proto__ === Object.prototype);

第一和第二个表达式返回true,但第三个表达式返回false。我不确定为什么它返回false,因为根据下面的图片,它应该返回true。 Inheritance 在这张图片中,您可以注意到Function.prototype的__proto__属性指向Object.prototype。
请问是否有人能够帮我澄清这些概念?
1个回答

3
在这张图片中,你可以注意到Function.prototype的__proto__属性指向Object.prototype。
但是这不是你测试的内容!你测试的是Function.__proto__,实际上它等同于Function.prototype。请尝试使用以下代码:
console.log(Function.prototype.__proto__ === Object.prototype);

2
也许还需要注意的是,Function 的原型实际上是 Empty 函数。 - LJᛃ
你说得对。但是这会返回什么 console.log(Function.proto); 因为 function 也是 jS 中预定义的对象。 - Deepak Kumar Padhy
啊,现在我明白你的问题了... Function实际上是一个预定义的构造函数,而不是一个预定义的对象。你可以像调用new Point()new Object()一样调用new Function() - hugomg

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接