我一直在获取catchPhrase不是函数。我试图弄清楚为什么它不记录日志。当我使用代码中包含的其他方法时,它可以工作,但是此特定方法不起作用。
function Humanoid(humanoidAtts) {
GameObject.call(this, humanoidAtts);
CharacterStats.call(this, humanoidAtts);
this.faction = humanoidAtts.faction;
this.weapons = humanoidAtts.weapons;
this.language = humanoidAtts.language;
}
Humanoid.prototype = Object.create(CharacterStats.prototype)
Humanoid.prototype.greet = function(){
return `${this.name} offers a greeting in ${this.language}`
}
function Hero(heroAtts) {
Humanoid.call(this, heroAtts);
}
Hero.prototype = Object.create(GameObject.prototype);
Hero.prototype = Object.create(CharacterStats.prototype);
Hero.prototype = Object.create(Humanoid.prototype);
Hero.prototype.catchPhrase = function(){
return `${this.name} says, look you got blood on my dress`
}
英雄的定义进一步向下。
const hero = new Humanoid ({
createdAt: new Date(),
dimensions: {
length: 3,
width: 2,
height: 5,
},
hp: 20,
name: 'Bouncing Betty',
faction: 'Tot Land',
weapons: [
'Parasol',
'Tessen',
],
language: 'Tabaxi',
});
console.log(hero.catchPhrase());