I'm trying to use prototypal inheritance and its not working, everytime i try i keep getting undefined:
function HospitalEmployee(name) {
this._name = name;
this._remaningVacationDays = 20;
}
function Nurse() {}
Nurse.prototype = Object.create(HospitalEmployee.prototype)
const nurseOlynyk = new Nurse("Olynyk", ["Trauma", "Genetics"])
console.log(nurseOlynyk._remainingVacationDays) //Prints undefined
What am i doing wrong?
I need use Class and Extends for it same as :
class HospitalEmployee {
constructor(name){
this._name = name;
this._remaningVacationDays = 20;
}
}
class Nurse extends HospitalEmployee {
constructor(name, otherParams){
super(name);
this.otherParams = otherParams;
}
}
const nurseOlynyk = new Nurse("Olynyk", ["Trauma", "Genetics"])
console.log(nurseOlynyk)