// public 公有 在类里面,子类 类外面都可以访问
// protected 保护类型 在类里面,子类 都可以访问 ,类外面无法访问
//provate 私有 在类里面,子类 类外面都不可以访问
//属性不加修饰符默认公有public
class Person {
public name: string //公有属性 public关键词可省略
constructor(name: string) {
this.name = name;
}
getName(): string {
return this.name;
}
setName(name: string): void {
this.name = name;
}
}
var p = new Person(‘张三’);
console.log(p.getName());
p.setName(‘李四’);
console.log(p.getName());
TS中类的修饰符
猜你喜欢
转载自blog.csdn.net/Frazier1995/article/details/120596974
今日推荐
周排行