1. <!DOCTYPE html>
    2. <html lang="en">
    3. <head>
    4. <meta charset="UTF-8">
    5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
    6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
    7. <title>Document</title>
    8. </head>
    9. <body>
    10. <input type="text" id="text" />
    11. <script>
    12. /* 员工管理
    13. 公共类 公共属性和公共方法
    14. 1.写父类的时候
    15. 公共的- 提取的时候,是否所有子类都有这个属性和方法
    16. 2. super的用法
    17. 父类构造函数 super(...)
    18. 父类的方法 super.xxx()
    19. 3.重写父类方法
    20. 同名覆盖
    21. 4.多态
    22. 同一个方法 - 可以有很多个版本
    23. */
    24. class Staff{
    25. constructor(name, department, basicSalary){
    26. this.name = name;
    27. this.department = department;
    28. this.basicSalary = basicSalary;
    29. }
    30. // 薪资
    31. salary() {
    32. return this.basicSalary;
    33. }
    34. }
    35. // / super的作用
    36. class Coder extends Staff{
    37. constructor(name, department, basicSalary, language){
    38. super(name, department, basicSalary);
    39. this.language = language;
    40. }
    41. // 重写父类的方法
    42. salary(){
    43. // 程序员薪资计算方式
    44. const basic = super.salary();
    45. return Math.ceil(basic * 1.2);
    46. }
    47. }
    48. class Designer extends Staff{
    49. constructor(name, department, basicSalary, type){
    50. super(name, department, basicSalary);
    51. this.type = type;
    52. }
    53. // 重写父类的方法
    54. salary(){
    55. // 设计师薪资计算方式
    56. const basic = super.salary();
    57. return Math.ceil(basic + 800);
    58. }
    59. }
    60. // 多态 - 简化代码
    61. // 不去管实例怎么去实现
    62. const c = new Coder('张三', '技术部', 9000, 'js');
    63. const d = new Designer('韩梅梅', '设计部', 6000, '平面设计');
    64. </script>
    65. </body>
    66. </html>