I'm diving (or trying) into advanced javascript topics like prototypes, constructors, function properties, etc. and some facts lead me to conclusion, that javascript functions are also objects.
I know that datatype of functions is function
, since:
> typeof function(){}
'function'
but anyway:
- you can assign properties to a function (just like it was an object)
- function has its
length
attribute Function.prototype
's prototype isObject.prototype
(prototype chaining):> Object.getPrototypeOf(Function.prototype) === Object.prototype true
Can someone please make it clear whether javascript functions are objects? If so, why is typeof function == 'function'
and typeof [] == 'object'
; if not - how about the points I mentioned above?
Edit: one more question - what is a first class object?