constructor
является свойством объекта prototype
:
var ChildClass = function(){
}
alert(ChildClass.prototype.constructor == ChildClass); // alert true
Отношение теперь выглядит так:
+-------------------+ +--------------------+
| | | |
|ChildClass instance|---------->|ChildClass protoype |
| | | constructor prop |
+-------------------+ +--------------------+
Это свойство действительно указывает на ChildClass
function.
Если вы переопределите ChildClass.prototype
, то child.constructor
будет найден в цепочке прототипов и будет ссылаться на:
ParentClass.prototype.constructor
, поскольку ChildClass.prototype
теперь является экземпляромParentClass
который наследуется от ParentClass.prototype
:
+-------------------+ +--------------------+ +---------------------+
| | | | | |
|ChildClass instance| ---> |ParentClass instance| ---> |ParentClass prototype|
| | | | | constructor prop |
+-------------------+ +--------------------+ +---------------------+
ParentClass.prototype.constructor
, конечно, будет указывать на ParentClass
.