kingBook

导航

TypeScript set和get

class Person {
    constructor() {
    }

    private _name:string;

    public get name():string{
        return this._name;
    }

    public set name(name:string){//不能定义返回类型,如: ":void"
        this._name = name;
    }
}

posted on 2020-12-04 18:01  kingBook  阅读(1193)  评论(0编辑  收藏  举报