mixins .
const PersonMixin = Base => class extends Base {
grew(years) {
return this.set("age", this.age + years);
}
};
const PersonBase = PersonMixin(new Immutable.Record({name: null, age: null}));
class Person extends PersonBase {}
const AcademicanBase = PersonMixin(new Immutable.Record({name: null, age: null, title: null}));
class Academician extends AcademicanBase {
constructor({name, age, title}) {
super({name, age, title});
}
}
var a = new Academician({name: "Bob", age: 50, title: "Assoc. Prof"});
console.log(a);
console.log(a.grew(10).age);
a.title = "Prof";