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?
1 Answer 1
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);
3 Comments
Function is actually the Empty function.new Function() similarly to how you can call new Point() and new Object()