Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the prototype of a Function object in Javascript?

I have just written this snippet 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 returns true but the 3rd expression returns false.I am not sure why it returns false, because as per the below image, it is supposed to return true. Inheritance

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

Could anyone please clear my concepts?

like image 846
Deepak Kumar Padhy Avatar asked Oct 20 '22 01:10

Deepak Kumar Padhy


1 Answers

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

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

console.log(Function.prototype.__proto__ === Object.prototype);
like image 97
hugomg Avatar answered Oct 22 '22 16:10

hugomg