在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
TypeScript的存储器,主要有get,set 属性,不知道有啥作用
let passcode = "secret passcode"; class Employee { private _fullName: string=""; get fullName(): string { return this._fullName; } set fullName(newName: string) { if (passcode && passcode == "secret passcode") { this._fullName = newName; } else { console.log("Error: Unauthorized update of employee!"); } } } let employee = new Employee(); employee.fullName = "Bob Smith"; if (employee.fullName) { //alert(employee.fullName); console.log(employee.fullName); }
|
请发表评论