Advertisement
Guest User

People

a guest
Oct 23rd, 2020
581
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solution() {
  2.   class Employee {
  3.     constructor(name, age) {
  4.       if (new.target === Employee) {
  5.         throw new Error("Cannot make instance of abstract class Employee.");
  6.       }
  7.  
  8.       [this.name, this.age, this.salary, this.tasks] = [name, age, 0, []];
  9.     }
  10.  
  11.     work() {
  12.       let current = this.tasks.shift();
  13.       console.log(`${this.name} ${current}`);
  14.       this.tasks.push(current);
  15.     }
  16.  
  17.     getSalary() {
  18.       return this.salary;
  19.     }
  20.  
  21.     collectSalary = () =>
  22.       console.log(`${this.name} received ${this.getSalary()} this month.`);
  23.   }
  24.  
  25.   class Junior extends Employee {
  26.     constructor(name, age) {
  27.       super(name, age);
  28.       this.tasks = ["is working on a simple task."];
  29.     }
  30.   }
  31.  
  32.   class Senior extends Employee {
  33.     constructor(name, age) {
  34.       super(name, age);
  35.       this.tasks = [
  36.         "is working on a complicated task.",
  37.         "is taking time off work.",
  38.         "is supervising junior workers.",
  39.       ];
  40.     }
  41.   }
  42.  
  43.   class Manager extends Employee {
  44.     constructor(name, age) {
  45.       super(name, age);
  46.       this.dividend = 0;
  47.       this.tasks = ["scheduled a meeting.", "is preparing a quarterly report."];
  48.     }
  49.  
  50.     getSalary() {
  51.       return super.getSalary() + this.dividend;
  52.     }
  53.   }
  54.  
  55.   return { Employee, Junior, Senior, Manager };
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement