-
-
Save ilearnjavascript/4c40959317c49f5681ebebb87b825546 to your computer and use it in GitHub Desktop.
es6 - classes - 13.js
This file contains 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
// base class | |
class es6_Person { | |
constructor(firstname, lastname) { | |
this.firstname = firstname; | |
this.lastname = lastname; | |
} | |
greet() { | |
console.log('Hello I am ' + this.firstname + ' ' + this.lastname); | |
} | |
} | |
// subclass | |
class es6_Soldier extends es6_Person { | |
constructor(firstname, lastname, weapon) { | |
super(firstname, lastname); | |
this.weapon = weapon; | |
} | |
shoot() { | |
console.log(`Peng Peng with ${this.weapon}`); | |
} | |
} | |
var janeTheSoldier = new es6_Soldier('Jane', 'Doe', 'Shotgun'); | |
janeTheSoldier.greet(); | |
janeTheSoldier.shoot(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment