I'm trying to wrap my head around Javascript inheritance and wanted to check if my understanding is correct. When I declare Javascript function in JS like that:
function Animal() {
}
Now first questions:
I declare
Function
object. This is no different from e.g.Array
that JS comes with.Array
is alsoFunction
object natively provided by JS is that right? And so isObject
andRegExp
and others? Is that right?Its incorrect to say that this object inherits from
Function
but can someone explain to me why? Is this because there is no formal class used as in Java and other languages? Or is it becauseAnimal
takes properties of actual existing object rather then sort of blueprint that class is in other languages? Is there any other reason?
Clarification on the above will be much appreciated, cheers,
EDIT: My question seems to create confusion so I should clarify.
In point 1 I'm not asking what Array returns. I'm simply trying to confirm my understanding that the function Animal
and Array
both have in common that their [[Prototype]] property reference the same Function.prototype
and so both are Function
objects. If I understand correctly Animal
is different from Array
however cause Animal.prototype
and Array.prototype
is obviously different.
In point 2 I'm looking for explanation why its incorrect to say that Animal "inherits" from Function.
I hope this makes more sense, thank you all