我正在学习 JS,并且遇到了一篇关于 JS 中的对象组合模式的有趣文章。我想知道这段代码:
let Magic = (superclass) => class extends superclass {
shout() {
if (super.shout) super.shout();
console.log('Power and wisdom.');
}
};
let Fighting = (superclass) => class extends superclass {
shout() {
if (super.shout) super.shout();
console.log('Strength an courage.');
}
};
class Creature {
constructor(name) {
this.name = name;
}
shout() {
console.log(`I'm ${this.name}! Oorah!!`);
}
};
class DwarfWizard extends Fighting(Magic(Creature)) {
courseObjects(object = {}) {
object.curse = true;
return object;
}
}
new DwarfWizard('Thordalf').shout();
// "I'm Thordalf! Oorah!! Power and wisdom. Strength an courage."
类中函数的目的是courseObjects
什么DwarfWizard
?
courseObjects(object = {}) {
object.curse = true;
return object;
}
即使我注释掉该函数,我仍然得到相同的结果,所以我想知道它的目的是什么?