# Ví dụ về kế thừa prototype ngang theo function constructor. Liên quan đến hàm call(), sẽ có bài chi

```
function Hero(name,level) {
	this.name = name;
	this.level = level;
}
function Warrior(name,level,weapon) {
	Hero.call(this, name, level);
	this.weapon = weapon;
}
function Healer(name,level,spell) {
	Hero.call(this, name, level);
	this.spell = spell;
}
Warrior.prototype = Object.create(Hero.prototype);
Healer.prototype = Object.create(Hero.prototype);
Hero.prototype.greet = function() {
	return `${this.name} says Hello`;
}
Warrior.prototype.attack = function() {
	return `${this.name} attack with ${this.weapon}`;
}
var hero1 = new Warrior('Hero 1',1, 'axe');
var hero2 = new Healer('Hero 2',1,'cure');
console.log(hero1.greet());
console.log(hero2.greet());
console.log('bbbbbbbbbbb');
console.log(hero1.attack());
console.log(hero2.attack());
```

![](https://2726517656-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M1E4Gk2ppVKb4olmnun%2F-MGm5oADj9VUov78PaL6%2F-MGm9QiEcbXgosunT3fE%2FScreenshot_1.png?alt=media\&token=cec59691-402d-44c4-aaa1-d2a90da917e1)
