5

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?

0

1 Answer 1

3

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);
Sign up to request clarification or add additional context in comments.

3 Comments

Maybe also note that the prototype of Function is actually the Empty function.
You are correct. But what does this would return console.log(Function.__proto__); As function is also a predefined Object in jS.
Ah, now I understand your question... Function is actually a predefined constructor function, not a predefined object. You can call new Function() similarly to how you can call new Point() and new Object()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.