| 1 | /// 类 :继承和成员修饰符 |
| 2 | class Dog { |
| 3 | constructor(name: string) { |
| 4 | this.name = name |
| 5 | } |
| 6 | // protected constructor(name: string) { //这个类不能被实例化,只能被继承 |
| 7 | // this.name = name |
| 8 | // } |
| 9 | name: string |
| 10 | run() {} |
| 11 | protected pro() {} //受保护成员,只能在类和子类中访问,不能在类的实例中访问 |
| 12 | readonly legs: number = 4 |
| 13 | static food: string = 'bones' // 类的静态成员,只能通过类名调用,不能通过实例调用 |
| 14 | } |
| 15 | |
| 16 | console.log(Dog.prototype) |
| 17 | let dog = new Dog('tiny') |
nothing calls this directly
no outgoing calls
no test coverage detected