New OOP features of JavaScript
Working Sample
class Human {
constructor(name, gender) {
this.name = name;
this.gender = gender;
}
static getGenderFemale() {
return "female";
}
static getGenderMale() {
return "male";
}
}
class MaleHuman extends Human {
constructor(name) {
super(name, Human.getGenderMale());
}
}
class FemaleHuman extends Human {
constructor(name) {
super(name, Human.getGenderFemale());
}
}
var jack = new Human("Jack", Human.getGenderMale());
console.log(jack);
var peter = new MaleHuman("Peter");
console.log(peter);
var sarah = new FemaleHuman("Sarah");
console.log(sarah);
Working Sample
class Human {
constructor(name, gender) {
this.name = name;
this.gender = gender;
}
static getGenderFemale() {
return "female";
}
static getGenderMale() {
return "male";
}
}
class MaleHuman extends Human {
constructor(name) {
super(name, Human.getGenderMale());
}
}
class FemaleHuman extends Human {
constructor(name) {
super(name, Human.getGenderFemale());
}
}
var jack = new Human("Jack", Human.getGenderMale());
console.log(jack);
var peter = new MaleHuman("Peter");
console.log(peter);
var sarah = new FemaleHuman("Sarah");
console.log(sarah);