5.抽象类.js 466 B

123456789101112131415161718192021
  1. (function () {
  2. /***
  3. * 抽象类 与其他类差别不大
  4. * abstract
  5. * 抽象类不是为了实例化对象
  6. * 他是因为要继承而产生的
  7. */
  8. class Animal {
  9. constructor(name) {
  10. this.name = name;
  11. }
  12. }
  13. class Dog extends Animal {
  14. say() {
  15. console.log("我叫" + this.name);
  16. }
  17. }
  18. let dog1 = new Dog('旺财a');
  19. console.log(dog1, 'dog1');
  20. dog1.say();
  21. })();