TS - private,protected,public使用

class Lee {
    private name: string // 私有访问
    protected age: number // 私有或子类可访问
    public sex: string // 默认公开
    constructor(theName?: string, age?: number, sex?: string) {
        this.name = theName
        this.age = age
        this.sex = sex
    }
    logName() {
        console.log(this.name); // 'dxw'
    }
}

let myLee = new Lee('dxw', 25, '男')
myLee.logName()

// let myLee = new Lee('str').name // 属性“name”为私有属性,只能在类“Lee”中访问。
// let myLee = new Lee().age // 属性“age”受保护,只能在类“Lee”及其子类中访问。

class Child extends Lee {
    constructor() {
        super('str', 18)
    }
    getAge() {
        console.log(this.age); // 18
    }
}

let myChild = new Child()
myChild.getAge()