constructoris a property of an object prototype:
var ChildClass = function(){
}
alert(ChildClass.prototype.constructor == ChildClass);
Now the relation is as follows:
+-------------------+ +--------------------+
| | | |
|ChildClass instance|---------->|ChildClass protoype |
| | | constructor prop |
+-------------------+ +--------------------+
This property points to a function ChildClass.
If you override ChildClass.prototype, then it child.constructorwill be checked in the prototype chain and will refer to:
ParentClass.prototype.constructor
as ChildClass.prototypeit is now an instance ParentClassthat inherits from ParentClass.prototype:
+-------------------+ +--------------------+ +---------------------+
| | | | | |
|ChildClass instance| ---> |ParentClass instance| ---> |ParentClass prototype|
| | | | | constructor prop |
+-------------------+ +--------------------+ +---------------------+
ParentClass.prototype.constructorof course point to ParentClass.
source
share