Some points to consider:
Object
is a function
It can be used to convert a primitive to an object. Like Object("test")
will create a String
instance.
There is a constructor for functions
The constructor for functions is Function
. It is not commonly done, but you can create a function by calling this constructor. For example: new Function("alert('test')")
returns a function that when called will display an alert.
Functions which are created with function
statements, expressions, arrow function syntax,... also have as constructor this Function
. So for instance, eval.constructor === Function
is a true expression. The same goes for Object.constructor === Function
. You can do this for any function.
Where to find the a function's prototype object?
Like every constructor, Function
has a prototype
property. That object defines the prototype properties and methods that all functions inherit. We can find that prototype object via Function.prototype
, or we can find it by taking a Function
instance (i.e. a function), and getting its prototype object. This we do by calling Object.getPrototypeOf
on a specific function.
Equalities
And so we can see that all of the following are equal:
var a = Object.getPrototypeOf(eval);
var b = Object.getPrototypeOf(parseInt);
var c = Object.getPrototypeOf(function () {});
var d = Object.getPrototypeOf(RegExp);
var e = Object.getPrototypeOf(Object);
var f = Function.prototype;
// All true:
console.log(a === f, b === f, c === f, d === f, e === f);