Inheritance on J.S

https://www.codecademy.com/courses/learn-javascript-classes/lessons/classes/exercises/inheritance-v?action=resume_content_item&course_redirect=introduction-to-javascript

Hi! why exactly on the inheritance V exercise when adding a method to the child class the console will reference error if I type the method like:
this.addCertifications(certifications) {
this._certifications.push(newCertification);
}
Nevertheless when I take the first this. everything starts working right? the code ends up like:

class Nurse extends HospitalEmployee {
constructor(name, certifications) {
super(name);
this._certifications = certifications;
}

get certifications() {
return this._certifications;
}

addCertification(newCertification) {
this._certifications.push(newCertification);
}
}

1 Like

For what I know, the this keyword is used to reference already existing variables or methods inside a class. Therefore, it would make no sense for you to define a new method using the this keyword.

Hope this helps! :slightly_smiling_face:

2 Likes