Provided the following code:
class Person {
constructor(name) {
this.name = name;
}
sayHello() {
console.log('Hello, my name is ' + this.name);
}
sayHelloAndBy() {
this.sayHello();
console.log('Bye');
}
}
class Student extends Person {
constructor(name, grade) {
super(name);
this.grade = grade;
}
sayHello() {
console.log(`Hi, I'm a studend and my name is ` + this.name);
}
}
let b = new Student("Some guy", 5);
b.sayHelloAndBy();
I would like to figure out a way of calling sayHello as defined in Person and not in Student. Is it possible ?
In php there is the self:: which allows one to do this, but I'm not sure if JS has a similar concept.
superin methods to refer to an overridden parent method.Person.prototype.sayHello.call(this)super. sayHellowould be the one that you are looking for