0

If you look at Object in Chrome DevTools you'll see that it's prototype property points towards an object, and I expect this.
Object

Functions prototype property looks like it points towards a function which I find suprising.
Function

First of all, is this true? And if so, is there any reason why Function's prototype key points towards a function object instead of just a plain object? (Are there any big implications to this?)

tonitone120
  • 1,920
  • 3
  • 8
  • 25
  • 1
    It has always been that way; it doesn't really have much of an effect on anything. A function object *is* an object, after all. – Pointy Aug 02 '20 at 13:05
  • It does point towards an object, the keys are just functions. Functions in js are function-object combos – Rohit Kashyap Aug 02 '20 at 13:05
  • @RohitKashyap the question is about why `Function.prototype` is itself a built-in function object instead of a plain object. – Pointy Aug 02 '20 at 13:07
  • @Pointy okay, good to know – tonitone120 Aug 02 '20 at 13:11
  • @Pointy you literally just wrote the same thing that I did – Rohit Kashyap Aug 02 '20 at 13:14
  • @RohitKashyap perhaps I misunderstood your comment, in particular the phrase "the keys are just functions". The Function constructor is unusual among the built-in objects in that its prototype object is itself a function. All other prototypes of built-in objects are plain objects. – Pointy Aug 02 '20 at 13:31

1 Answers1

0

Javascript follows Prototypal-Inheritance. And Object and Function are nothing but Constructor Functions. Any subsequent function or object created will hence inherit properties from the prototype (*).

With this pattern, it is obvious that a prototype of an Object points to an object and that of a function points to a function. It may be a bit confusing, hence it is recommended to follow this

"The Function prototype object is specified to be a function object to ensure compatibility with the ECMAScript code that was created prior to the ECMAScript 2015 specification."

(*) Be noted that functions are objects (you can add properties to them) in Javascript.

Prashanth Wagle
  • 354
  • 5
  • 8