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:
userInfo
has no ownconstructor
property.- The value of
userInfo
's [[Prototype]] internal slot isFunction.prototype
. Function.prototype
has an ownconstructor
property, whose value isFunction
.
Function.constructor
is Function
too because of the same reason:
Function
has no ownconstructor
property.- The value of
Function
's [[Prototype]] internal slot isFunction.prototype
. Function.prototype
has an ownconstructor
property, whose value isFunction
.
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
.