If the functions are objects in javascript, why does the function.constructor point to Function instead of Object?

advertisements

When creating the following function from the window object like this,

         function userInfo() {};

how come the userInfo.constructor displays Function instead of Object since functions are objects?

It even display Function instead of Object when using the following,

         Function.constructor


userInfo.constructor is Function because:

  1. userInfo has no own constructor property.
  2. The value of userInfo's [[Prototype]] internal slot is Function.prototype.
  3. Function.prototype has an own constructor property, whose value is Function.

Function.constructor is Function too because of the same reason:

  1. Function has no own constructor property.
  2. The value of Function's [[Prototype]] internal slot is Function.prototype.
  3. Function.prototype has an own constructor property, whose value is Function.

That is, Function instances (like userInfo or Function itself) inherit a constructor property from Function.prototype, which can be used to know they are instances of Function.