This.name=name? why


#1

There are two questions :
1 Please look at the code below
i donot understand this._name=name ?why?
2 and the end :
takeVacationDays(daysOff){
this._remainingVacationDays= this._remainingVacationDays-daysOff
’this’is useful ?why we must write the code like this ?
because this replace Surgeon ?

class Surgeon {
constructor(name, department) {
this._name = name;
this._department = department;
this._remainingVacationDays=20;
}
get name(){
return this._name;
}
get department(){
return this._department;
}
get remainingVacationDays(){
return this._remainingVacationDays
}
takeVacationDays(daysOff){
this._remainingVacationDays= this._remainingVacationDays-daysOff

}
}

const surgeonCurry = new Surgeon(‘Curry’, ‘Cardiovascular’);
const surgeonDurant = new Surgeon(‘Durant’, ‘Orthopedics’);


#2

you need to understand the this keyword, i highly recommend the following documentation:

which covers a lot of ground when it comes to this keyword


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.