super Methods Javascript
class Person {
constructor(name, email) {
this.name = name;
}
toString() {
return `name: ${this.name}`;
}
}
class Teacher extends Person {
constructor(name, subject) {
super(name);
this.subject = subject;
}
toString() {
return super.toString() + ` subject: ${this.subject}`;
}
}
const teacher = new Teacher('testname', 'testSubject');
console.log(teacher.toString());
This is from an old stackoveflow answer of mine…