I have a class, SuperClass"and this class must be inherited (via the prototype chain) on SubClassAand SubClassB. However, although inheritance works for SubClassA, it does not execute for SubClassB. The code below:
function SuperClass(childCell){
this.childCell = childCell;
this.children = new Array(9);
for(i=0; i<9; i++) {
this.children[i] = new this.childCell();
}
}
function SubClassA(){
this.num = 1;
}
SubClassA.prototype = new SuperClass(SubClassB);
function SubClassB(){
this.num = 2;
}
SubClassB.prototype = new SuperClass(SubClassC);
function SubClassC(){
this.num = 3;
}
var x = new SubClassA();
In this code, I set xto an object SubClassA, and this should in turn give me a property childrencontaining 9 SubClassBobjects. He does it right, but, in turn, each object SubClassBmust contain 9 SubClassCobjects. However, after checking the console, I found that none of the objects SubClassBactually contained properties childCellor childrenthat it had to inherit through the prototype.
, x.children[0] SubClassB {num: 2} .
SubClassA, SubClassB?