0

Can anybody explain/elaborate on the following:

enter image description here

I have checked this on console.

Function.prototype and Function.__proto__ point to the same object. It is also the same object that is referenced by Object.__proto__. Any custom function that you write or even the built-ins one (Array,String,Number) , have their .__proto__ point to this object.

Checking Function.prototype on console returns:

ƒ () { [native code] }

Interestingly, this object's .__proto__ point to Object.prototype object.

I do understand that Object.prototype.__proto__ is null which is where the prototype chain stops.

Found the image here

asked Mar 20, 2021 at 18:21
6
  • 1
    This might help you understand - stackoverflow.com/questions/9959727/… & developer.mozilla.org/en-US/docs/Learn/JavaScript/Objects/… Commented Mar 20, 2021 at 19:05
  • Every function (including Function() and Object()) inherits from Function.prototype, which holds function methods like .call/.apply/.bind, and in turn inherits from Object.prototype. Commented Mar 20, 2021 at 23:15
  • @Bergi Does this not look strange to you that the Function object has its both .__proto__ and .prototype property point to a same object. String.prototype and String.__proto__ point to two different objects. Moreover, what exactly is Function.prototype object? I can't see what is inside it. It returns ƒ () { [native code] }. Is it of type function or object. You can see what is inside Function() object, Object() and Obect.prototype object. But not this one. Commented Mar 21, 2021 at 7:02
  • 1
    @pragun Use console.dir to print it as an object - Function.prototype is a function for some reason. And no, Function.prototype === Obect.getPrototypeOf(Function) isn't strange if you consider what they mean, but it's special indeed as this only happens on a "metaclass" where the class is an instance of itself. Commented Mar 21, 2021 at 11:16
  • 1
    The reason why Function.prototype remains a Function object is due to backwards compatibility. Basically, there is a change in ES specification regarding how should a prototype object of an object be treated. For eg, in ES5, String.prototype is an String object but in ES6, its an object of type Object. The exception to such changes are "prototype objects" of Function and Array. You can read more here: stackoverflow.com/questions/32928810/… Commented Aug 14, 2022 at 11:48

0

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.