
typescript 公共,私有与受保护的修饰符
发布日期:2021-05-13 01:00:17
浏览次数:16
分类:博客文章
本文共 2588 字,大约阅读时间需要 8 分钟。
public������
������������������������������������������������������public���������������������������������������������������������������������������������
class Person{ name:string sex:string age:number // ���������������public constructor(name:string, sex:string, age:number){ this.name = name this.sex = sex this.age = age } show_name():void{ console.log('������������������������', this.name) }}let lcs = new Person('lcs', 'man', 21)console.log('������������������', lcs.name)lcs.show_name()
private������
������������������������������������������������������private���������������������������������������������������������
class Person{ private name:string // ���������name���������private sex:string age:number constructor(name:string, sex:string, age:number){ this.name = name this.sex = sex this.age = age } show_name():void{ console.log('������������������������', this.name) }}class Teacher extends Person{ salary: number constructor(name:string, sex:string, age:number,salary:number){ super(name,sex,age) this.salary = salary } show():void{ console.log('������������������������', this.name, this.salary.toString()) }}let lcs = new Person('lcs', 'man', 21)let t = new Teacher('lcs', 'man',21,31232)t.show()console.log('������������������', lcs.name)lcs.show_name()
���������������������������������
������������������name���������private���������������Person������������������������������������������������������������������������������������������������������������������������������������������������������������������
protected������
���������protected���������������������������������������������������������������������������������������
class Person{ protected name:string // ���name������protected sex:string age:number constructor(name:string, sex:string, age:number){ this.name = name this.sex = sex this.age = age } show_name():void{ console.log('������������������������', this.name) }}class Teacher extends Person{ salary: number constructor(name:string, sex:string, age:number,salary:number){ super(name,sex,age) this.salary = salary } show():void{ console.log('������������������������', this.name, this.salary.toString()) }}let lcs = new Person('lcs', 'man', 21)let t = new Teacher('lcs', 'man',21,31232)t.show()console.log('������������������', lcs.name)lcs.show_name()
���������������������
������������������������������������������������
发表评论
最新留言
不错!
[***.144.177.141]2025年05月04日 10时57分15秒
关于作者

喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
小程序提交新数据后如何返回上一页并刷新数据?
2021-05-14
qt c++实现的ai贪吃蛇吃满屏幕,超详细!(二)ai的具体实现
2021-05-14
linux 查看log日志相关命令
2021-05-14
IDEA 2019 安装 mybatis-plus插件
2021-05-14
div 实现光标悬停变成手型
2021-05-14
layer.confirm 无效
2021-05-14
Java 回调机制
2021-05-14
7、回归和特征选择
2021-05-14
pycharm使用(新建工程、字体修改、调试)
2021-05-14
什么是Numpy、Numpy教程
2021-05-14
Python学习笔记——元组
2021-05-14
异常声音检测
2021-05-14
PCB学习笔记——AD17如何添加新的封装
2021-05-14
PCB学习笔记——AD17对芯片悬空引脚的操作
2021-05-14
numpy版本问题
2021-05-14
无法打开文件“opencv_world330d.lib”的解决办法
2021-05-14
maven项目通过Eclipse上传到svn上面,再导入到本地出现指定的类找不到的问题
2021-05-14