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.
 
 
 
 
 

32 lines
593 B

// 可见性修饰符:private 表示私有的,只能在当前类中可见(只能在类内部使用),对实例对象以及子类都是不可见的
// 父类
class Animal {
// _run_ 方法是私有的
private _run_ () {
console.log('321')
}
// 受保护的
protected move() {
this._run_()
console.log('654')
}
// 公开的
run() {
this._run_()
this.move()
console.log('gogogo')
}
}
const a = new Animal()
class Dog extends Animal {
bark() {
console.log('123')
}
}
const d = new Dog()