Advertisement
Guest User

03.People - Fixed

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