class Person {
constructor(name) {
this.name = name;
}
sayName() {
console.log('My name is ', this.name + '!');
}
sayHi() {
console.log('Hello everybody!');
}
}
class AngryPerson extends Person {
constructor(name, phrase) {
super(name);
this.phrase = phrase
}
sayHi() {
console.log('I just fucking hate you all');
}
saySomethingElse() {
console.log(this.phrase);
}
}
Jim = new Person('Jim');
// Object { name: "Jim" }
Jim.sayName();
// My name is Jim!
Jim.sayHi();
// Hello everybody!
Jim.saySomethingElse();
// TypeError: Jim.saySomethingElse is not a function
Bob = new AngryPerson('Bob', 'Please, leave me alone');
// Object { name: "Bob", phrase: "Please, leave me alone" }
Bob.sayName();
// My name is Bob!
Bob.sayHi();
// I just fucking hate you all
Bob.saySomethingElse();
// Please, leave me alone