What is a prototype of a Function object in Javascript?

I just wrote this piece of code.

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); 

The first two expressions return true, but the third expression returns false. I am not sure why it returns false because, as shown in the figure below, it should return true. Inheritance

In the image, you may notice that the Function.prototype __ proto __ property points to Object.prototype.

Can anyone clear my mind?

+5
source share
1 answer

In the image, you may notice that the Function.prototype __ proto __ property points to Object.prototype.

But this is not what you tested! You tested Function.__proto__ , which is actually equal to Function.prototype . Try instead:

 console.log(Function.prototype.__proto__ === Object.prototype); 
+3
source

Source: https://habr.com/ru/post/1202538/


All Articles