Last active
March 13, 2018 23:05
-
-
Save DavidMellul/ae6005b3b75e17c948db0385d2d368b7 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; | |
| 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