I am a self taught web developer and am still trying to come to grips with some JavaScript fundamentals. Below are some quotes extracted from Douglas Crockford’s Good Parts.
“Functions in JavaScript are Objects”
“In JavaScript, arrays are objects, functions are objects, regular expressions are objects, and, of course, objects are objects”
“Every object is linked to a prototype object from which it can inherit properties” (namely constructor, toString, …)
If Function is an Object then why
console.log(typeof Function); // function
is its type a function and not object
console.log(Object.constructor); // Function()
is it the constructor of its ‘parent’
console.log(Function.constructor); // Function()
puzzled so the constructor is in-fact a function?
console.log(typeof Function.prototype); // Function
is the type of its prototype a function and not an object? i thought it inherited from Object
Answers to these questions will greatly assist my understanding on JavaScript.
Because the typeof operator is defined like that, probably for usability:
returns an Implementation-defined value that may not be "undefined", "boolean", "number", or "string".
[[Call]]is an internal property of an object that identifies the object as a function (callable). A non-native object is an object provided by the host (e.g. browser), such as a DOM object or an instance of ActiveXObject.Why wouldn’t it be? Constructors are functions. Instances can only be constructed using functions.
Object.constructoris a function, but it’s also an object. See the following:Also, from the ECMAScript speficiation:
And also, to answer your final puzzlement: