<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title></head><body> <input type="text" id="text" /> <script> /* 员工管理 公共类 公共属性和公共方法 1.写父类的时候 公共的- 提取的时候,是否所有子类都有这个属性和方法 2. super的用法 父类构造函数 super(...) 父类的方法 super.xxx() 3.重写父类方法 同名覆盖 4.多态 同一个方法 - 可以有很多个版本 */ class Staff{ constructor(name, department, basicSalary){ this.name = name; this.department = department; this.basicSalary = basicSalary; } // 薪资 salary() { return this.basicSalary; } } // / super的作用 class Coder extends Staff{ constructor(name, department, basicSalary, language){ super(name, department, basicSalary); this.language = language; } // 重写父类的方法 salary(){ // 程序员薪资计算方式 const basic = super.salary(); return Math.ceil(basic * 1.2); } } class Designer extends Staff{ constructor(name, department, basicSalary, type){ super(name, department, basicSalary); this.type = type; } // 重写父类的方法 salary(){ // 设计师薪资计算方式 const basic = super.salary(); return Math.ceil(basic + 800); } } // 多态 - 简化代码 // 不去管实例怎么去实现 const c = new Coder('张三', '技术部', 9000, 'js'); const d = new Designer('韩梅梅', '设计部', 6000, '平面设计'); </script></body></html>