Advertisement
karlakmkj

Class - constructor, getter & methods

Dec 18th, 2020
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Surgeon {
  2.   constructor(name, department) {
  3.     this._name = name;
  4.     this._department = department;
  5.     this._remainingVacationDays = 20;
  6.   }
  7.  
  8.   //use getter for private properties
  9.   get name(){
  10.     return this._name;
  11.   }
  12.  
  13.   get department(){
  14.     return this._department;
  15.   }
  16.  
  17.   get remainingVacationDays(){
  18.     return this._remainingVacationDays;
  19.   }
  20.  
  21.   //method created
  22.   takeVacationDays(daysOff){
  23.     this._remainingVacationDays -= daysOff;
  24.   }
  25. }
  26.  
  27. const surgeonCurry = new Surgeon('Curry', 'Cardiovascular');
  28. const surgeonDurant = new Surgeon('Durant', 'Orthopedics');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement