Last active
March 13, 2018 22:57
-
-
Save DavidMellul/ceda31046608d47c7cc13d60358955ca to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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