You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

23 lines
504 B

2 years ago
  1. // 类的两种继承方式:1.extends(继承父类) 2.implements(实现接口)
  2. // 父类
  3. class Animal {
  4. move() {
  5. console.log('666')
  6. }
  7. }
  8. // 第一种:extends(继承父类)
  9. // 子类 Dog 继承 父类 Animal,子类 Dog 具有父类 Animal 的属性和方法
  10. class Dog extends Animal {
  11. // 子类自己的属性和方法
  12. name = 'Max'
  13. brak() {
  14. console.log('8888')
  15. }
  16. }
  17. // 实例化子类 Dog
  18. const d = new Dog()
  19. d.move()
  20. d.brak()
  21. console.log(d.name)