Hello everyone
I have a small doubt related to the inheritance chapter provided in
the book mentioned in the subject.
The chapter explains combination inheritance, wherein a diagram is
given to explain the following code:
function SuperType(name){
this.name = name;
this.colors = [“red”, “blue”, “green”];
}
SuperType.prototype.sayName = function(){
alert(this.name);
};
function SubType(name, age){
SuperType.call(this, name); //second call to SuperType()
this.age = age;
}
SubType.prototype = new SuperType(); //first call to SuperType()
};
The diagram shows that when SubType.prototype = new SuperType(); is
executed, a new instance of SuperType is assigned as the prototype of
the SubType object. In the end, the instance contains properties :
___proto__ , name and colors.
But in addition, that instance is also shown to have a constructor
property.
It is mentioned in the same chapter that when SubType.prototype = new
SuperType(); is executed, the constructor gets overwritten, so in this
case there should be just an object having 3 properties ( __proto__,
name and colors ) instead of 4.
Can someone please clarify this issue.
Thank you.
--
To view archived discussions from the original JSMentors Mailman list:
http://www.mail-archive.com/[email protected]/
To search via a non-Google archive, visit here:
http://www.mail-archive.com/[email protected]/
To unsubscribe from this group, send email to
[email protected]