Skip to content

Instantly share code, notes, and snippets.

@DavidMellul
Last active March 13, 2018 22:57
Show Gist options
  • Select an option

  • Save DavidMellul/ceda31046608d47c7cc13d60358955ca to your computer and use it in GitHub Desktop.

Select an option

Save DavidMellul/ceda31046608d47c7cc13d60358955ca to your computer and use it in GitHub Desktop.
function Champion(category = 'Champion') {
this.category = category;
};
function Warrior() {
Champion.call(this,'Warrior');
}
function Dwarf() {
Champion.call(this,'Dwarf');
}
function Rogue() {
Champion.call(this,'Rogue');
}
// Ugly part you should avoid, based on the above code
const champions = [new Rogue(), new Warrior(), new Dwarf()];
// Using ES6 of
for(hero of champions) {
if(hero.category == 'Warrior')
console.log('Hey, a warrior is here');
else if(hero.category == 'Rogue')
console.log('Hey, a Rogue is here');
else
console.log('Hey, a Dwarf is here');
}
// => Hey, a Rogue is here | Hey, a Warrior is here | Hey, a Dwarf is here
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment