JS: Function.prototype

By Xah Lee. Date: . Last updated: .

What Is Function.prototype

Purpose

Function.prototype is the parent of all function objects.

console.log(Reflect.getPrototypeOf(function f() {}) === Function.prototype);
console.log(Reflect.getPrototypeOf((x) => 3) === Function.prototype);

[see Prototype and Inheritance]

Type

interesting is that

Type of Function.prototype is function object.

console.assert(typeof Function.prototype === "function");

This was done for backward compatibility with pre-ES2015 code that treated Function.prototype as callable. Other built-in prototypes (Object.prototype, Array.prototype, String.prototype, etc.) are ordinary objects and therefore have typeof === "object".

Function.prototype(args) is not useful. It takes any number of arguments, and always return undefined.

// Function.prototype() takes any arg, return undefined
console.assert(Function.prototype() === undefined);
console.assert(Function.prototype(3) === undefined);
console.assert(Function.prototype(3, 4) === undefined);
console.assert(Function.prototype({}) === undefined);

Properties

Value Properties

Function Properties