根据各种来源(2ality,esdiscuss),应该能够将mixins添加到类中:
编辑发现类方法不可枚举,因此无法工作.编辑了下面的代码,但仍然没有快乐
class CartoonCharacter {
constructor(author) {
this.author = author;
}
drawnBy() {
console.log("drawn by", this.author);
}
}
// THIS CANNOT WORK
// class methods are not enumerable
// class Human {
// haveFun() {
// console.log("drinking beer");
// }
// }
let Human = Object.create({}, {
haveFun: {
enumerable: true,
value: function () {
console.log("drinking beer");
}
}
});
class Simpson extends Object.assign(CartoonCharacter, Human) {
constructor(author) {
super(author);
}
}
let homer = new …Run Code Online (Sandbox Code Playgroud)