Skip to content

Instantly share code, notes, and snippets.

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

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

Select an option

Save DavidMellul/ae6005b3b75e17c948db0385d2d368b7 to your computer and use it in GitHub Desktop.
function Champion(category = 'Champion') {
this.category = category;
this.sayHi = function() { console.log(`Hey, a ${this.category} is here`) };
};
function Warrior() {
Champion.call(this,'Warrior');
}
function Dwarf() {
Champion.call(this,'Dwarf');
}
function Rogue() {
Champion.call(this,'Rogue');
}
const champions = [new Rogue(), new Warrior(), new Dwarf()];
// Using ES6 of
for(hero of champions) {
hero.sayHi(); // Much cleaner
}
// => 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