1

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?

2
  • what browser are you on? or is this nodejs? Commented Jun 17, 2015 at 19:03
  • The results are the same on Chrome and Node. In Firefox, instead of function Empty() it just reports function() Commented Jun 17, 2015 at 19:23

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.