It seems that if you want the parent constructor to be executed by child instances, you have to explicitly call it from the child constructors (as in Python when you redefine __init__() in a child class):
- Code: Select all
var Parent = {
new: func(id=0) {
var obj = {parents: [Parent]};
obj.parentInit(id);
return obj;
},
parentInit: func(id=0) {
me.id = id;
},
getInfo: func {
print("no info\n");
},
getId: func {
print("id: ", me.id, "\n");
}
};
var Child = {
new: func(id=0) {
var obj = {parents: [Child, Parent]};
obj.parentInit(id);
return obj;
},
getInfo: func {
print("I am a Child\n");
}
};
var Dog = {
new: func {
var obj = {parents: [Dog, Parent]};
obj.parentInit();
return obj;
}
};
var child1 = Child.new(1);
var child2 = Child.new(2);
var dog = Dog.new();
child1.getInfo();
child1.getId();
child2.getInfo();
child2.getId();
dog.getInfo();
dog.getId();