What is the Empty function in JavaScript, and why is it undefined?

1.2k Views Asked by At

Why does the engine report that the function Empty() is the prototype of the native Function function in JavaScript, but that function is itself undefined (from the user's point of view)?

Function.prototype; // function Empty()
Function.__proto__; // function Empty()
Function.constructor; // function Function()

Empty(); // Uncaught ReferenceError: Empty is not defined

Object.prototype; // Object {}
Object.__proto__; // function Empty()
Object.constructor; // function Function()

Number.prototype; // Number {[[PrimitiveValue]]: 0}
Number.__proto__; // function Empty()
Number.constructor; // function Function()

String.prototype; // String {length: 0, [[PrimitiveValue]]: ""}
String.__proto__; // function Empty()
String.constructor; // function Function()

Boolean.prototype; // {[[PrimitiveValue]]: false}
Boolean.__proto__; // function Empty()
Boolean.constructor; // function Function()

Why not point all of those references to Empty() to null or some empty object?

1

There are 1 best solutions below

0
On

Why does the engine report that the function Empty() is the prototype of the native Function

Because the Function.prototype object is basically an empty function.

that function is itself undefined (from the user's point of view)?

I don't see what you mean, Function.prototype is pretty defined. If you mean the identifier Empty, there's no reason it would be a global variable just because it's used for the name of a function.

Why not point all of those references to Empty() to null?

Because that would destroy inheritance.

or some empty object?

It is an empty object - an empty function object. Why not a plain object? Because the spec says so.