Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In JavaScript, why typeof Function.prototype is "function", not "object" like other prototype objects?

Tags:

console.log(typeof String.prototype); // object console.log(typeof Number.prototype); // object console.log(typeof Object.prototype); // object console.log(typeof Boolean.prototype); // object  console.log(typeof Function.prototype); // function 

Why does typeof Function.prototype return "function", not "object" like other prototype objects?

Thank you!

like image 359
weilou Avatar asked Feb 01 '11 05:02

weilou


People also ask

Why TypeOf function is function?

The TypeOf function is an important tool when dealing with complex code. It allows a programmer to quickly check a variable's data type—or whether it's “undefined” or “null”—without going through the code line by line! Additionally, the TypeOf function can also check whether an operand is an object or not.

Is prototype an object in JavaScript?

Every object in JavaScript has a built-in property, which is called its prototype. The prototype is itself an object, so the prototype will have its own prototype, making what's called a prototype chain. The chain ends when we reach a prototype that has null for its own prototype.

Why is function prototype a function?

In computer programming, a function prototype or function interface is a declaration of a function that specifies the function's name and type signature (arity, data types of parameters, and return type), but omits the function body.

What is difference between __ proto __ and prototype?

prototype is a property of a Function object. It is the prototype of objects constructed by that function. __proto__ is an internal property of an object, pointing to its prototype. Current standards provide an equivalent Object.


1 Answers

This seems to be defined in ECMAScript 5:

15.3.4 Properties of the Function Prototype Object

The Function prototype object is itself a Function object (its [[Class]] is "Function") that, when invoked, accepts any arguments and returns undefined.

like image 165
leebriggs Avatar answered Nov 04 '22 23:11

leebriggs