| 1234567891011121314151617181920212223242526272829303132333435 |
- (function() {
- /**
- * readonly
- * static
- * private 私有的 只能使用类去进行获取修改
- * public 共有的
- * protected 受保护的 只能在当前类或者当前类的子类中访问
- */
- class Person {
- private name:string;
- protected age:number;
- constructor(name:string,age:number) {
- this.name = name;
- this.age = age;
- }
- getName() {
- return console.log(this.name)
- }
- get name1() {
- return this.name;
- }
- set name1(val) {
- this.name = val;
- }
- }
- let p = new Person("蜡笔小新",3);
- console.log(p,'修改前')
- // p.name = '图图';
- // console.log(p.name,'修改后')
- console.log(Person.name,'哈哈')
- p.getName()
- p.name1 = '图图';
- // p.age = 12;
- // console.log(p.name1,p.age)
- })()
|