I want to compose multiple objects into one. The super keyword should call corresponding parent object method. If parent's method is not present, it should call next parent's method and so on.
Example code that throws:
var base = {
runBusinessLogic() {
console.log('BASE');
}
}
var concrete = {
unrelatedExtraMethod() {
}
}
var addon = {
runBusinessLogic() {
super.runBusinessLogic(); // I expect this super call to call base.runBusinessLogic(..)
console.log('ADDON');
}
}
var layer2 = Object.setPrototypeOf(concrete, base);
var layer3 = Object.create(layer2, addon);
layer3.runBusinessLogic(); // throws "TypeError: layer3.runBusinessLogic is not a function"
I expect the layer3.runBusinessLogic(..) to call base.runBusinessLogic(..) and still have callable unrelatedExtraMethod on itself.
How to make the super keyword work as outlined?