function pluralParent(...parents) {
let DerivativeParent = function() {
for (let Parent of parents) {
Object.assign(this, new Parent());
}
};
DerivativeParent.prototype = new Proxy(DerivativeParent.prototype, { //Наследование свойств прототипа
get: (target, name) => {
if (target[name]) {
return target[name];
}
for (let Parent of parents) {
if (name in Parent.prototype) {
return Parent.prototype[name];
}
}
}
});
DerivativeParent = new Proxy(DerivativeParent, { //Наследование статичных свойств класса
get: (target, name) => {
if (target[name]) {
return target[name];
}
for (let Parent of parents) {
if (name in Parent) {
return Parent[name];
}
}
}
});
return DerivativeParent;
}
class Cat {
constructor() {
this.isACat = true;
}
meow() {
console.log("meow");
}
}
class Dog {
constructor() {
this.isADog = true;
}
bark() {
console.log("woof");
}
}
class CatDog extends pluralParent(Cat, Dog) {}
let catDog = new CatDog();
catDog.meow();
catDog.bark();
console.log(catDog);
Затестить можно в
babel repl в последнем файрфоксе.