gpt4 book ai didi

javascript - Javascript 中函数对象的原型(prototype)是什么?

转载 作者:搜寻专家 更新时间:2023-11-01 04:25:05 25 4
gpt4 key购买 nike

我刚刚写了这段代码。

 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。

谁能澄清我的概念?

最佳答案

In the image you can notice Function.prototype's __ proto __ property point to Object.prototype.

但这不是你测试的!你测试了Function.__proto__,它实际上等于Function.prototype。试试这个:

console.log(Function.prototype.__proto__ === Object.prototype);

关于javascript - Javascript 中函数对象的原型(prototype)是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25834616/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com