Being under the same parent class?


#1

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

i thought since they are both under the same parent class, that will be a no brainer, but it turns out even if it has been decleared above under the same parent class, lets say,

class Surgeon {
constructor(name, department) {
this._name = name;
this._department = department;
this._remainingVacationDays = 20;
this._age=18;
}

get age(){
return this._age;

changing:- NOTE:person
const surgeonCurry = new Surgeon(‘Curry’, ‘Cardiovascular’);
to
const personDurant = new Surgeon(‘Durant’, ‘Orthopedics’);

will still print out the value 18 for Durant.


#2

surgeonCurry and surgeonDurant are class instances

what? parent class is used when a class (child) inherits from another class (parent)

both surgeonCurry and surgeonDurant are instances of the same class, that much is true.

here:

this._age=18;

you don’t know a surgeons age, it would make more sense to determine the age when creating an instance, given then we can set a specific age for each instance. Make age part of the constructor, just like you did with name and department, then we can supply the age of the surgeon when we create class instance