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.

31 lines
593 B

2 years ago
  1. // 可见性修饰符:private 表示私有的,只能在当前类中可见(只能在类内部使用),对实例对象以及子类都是不可见的
  2. // 父类
  3. class Animal {
  4. // _run_ 方法是私有的
  5. private _run_ () {
  6. console.log('321')
  7. }
  8. // 受保护的
  9. protected move() {
  10. this._run_()
  11. console.log('654')
  12. }
  13. // 公开的
  14. run() {
  15. this._run_()
  16. this.move()
  17. console.log('gogogo')
  18. }
  19. }
  20. const a = new Animal()
  21. class Dog extends Animal {
  22. bark() {
  23. console.log('123')
  24. }
  25. }
  26. const d = new Dog()