constructor
is a property of the prototype
object:
var ChildClass = function(){
}
alert(ChildClass.prototype.constructor == ChildClass); // alert true
The relationship is now like this:
+-------------------+ +--------------------+
| | | |
|ChildClass instance|---------->|ChildClass protoype |
| | | constructor prop |
+-------------------+ +--------------------+
This property points indeed to the ChildClass
function.
If you override ChildClass.prototype
, then child.constructor
will be looked up in the prototype chain and will refer to:
ParentClass.prototype.constructor
as ChildClass.prototype
is now an instance of ParentClass
which inherits from ParentClass.prototype
:
+-------------------+ +--------------------+ +---------------------+
| | | | | |
|ChildClass instance| ---> |ParentClass instance| ---> |ParentClass prototype|
| | | | | constructor prop |
+-------------------+ +--------------------+ +---------------------+
ParentClass.prototype.constructor
will of course point to ParentClass
.