5.抽象类.js 530 B

1234567891011121314151617181920212223
  1. "use strict";
  2. (function () {
  3. /**
  4. * abstract 与 其他类大差不差
  5. * 不是为了实例化对象
  6. * 是因为继承才产生的类
  7. * 抽象类中方法没用具体内容 只有方法体
  8. * 在继承中写具体方法
  9. */
  10. class Toy {
  11. constructor(name) {
  12. this.name = name;
  13. }
  14. }
  15. class A extends Toy {
  16. say() {
  17. console.log(this.name + '说你好');
  18. }
  19. }
  20. let a = new A("迪迦奥特曼");
  21. console.log(a);
  22. a.say();
  23. })();