0
点赞
收藏
分享

微信扫一扫

ts get和set

 

 

 

class User {
// get、set方法的成员变量命名时建议在前面加 _
private _fullName: string;
//get 的用法
get fullName(): string{
return this._fullName;
}

// "set" 访问器必须正好具有一个参数
set fullName(fullName: string) {
this._fullName = fullName;
}
}

const c = new User();
// set 不需要调用方法 直接对象属性赋值
c.fullName = "GT";
// get 直接对象属性赋值

 



举报

相关推荐

0 条评论