Skip to content

Instantly share code, notes, and snippets.

@ilearnjavascript
Created March 27, 2019 23:41
Show Gist options
  • Save ilearnjavascript/4c40959317c49f5681ebebb87b825546 to your computer and use it in GitHub Desktop.
Save ilearnjavascript/4c40959317c49f5681ebebb87b825546 to your computer and use it in GitHub Desktop.
es6 - classes - 13.js
// 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