12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- // 属性 封装:令属性更安全
- (function(){
- /**
- * readonly 只读
- * public 公共的
- * private 私有的 只能在当前类中进行使用(访问及修改)
- * protected 受保护的 当前字段在当前类及当前子类中只能访问
- */
- // class Person {
- // public name:string;
- // private age:number;
- // constructor(name:string,age:number) {
- // this.name = name;
- // this.age = age;
- // }
- // /***
- // * 属性封装
- // * getter 获取属性值 get
- // * setter 设置属性值 set
- // */
- // get name1() {
- // return this.age+'1';
- // }
- // set name1(value:string) {
- // this.name = value
- // }
- // // getName() {
- // // return this.name;
- // // }
- // // setName(value:string) {
- // // return this.name = value;
- // // }
- // }
- // let p = new Person("孙悟空",10)
- // // p.setName("猪八戒")
- // // console.log(p.getName(),'实例化对象')
- // console.log(Person,'类')
- // // p.age = 12;
- // p.name1 = '唐僧'
- // console.log(p.name1)
- // class A {
- // public name:string;
- // public age:number;
- // constructor(name:string,age:number) {
- // this.name = name;
- // this.age = age;
- // }
- // }
- // class B {
- // constructor( public name:string,public age:number) {
- // this.name = name;
- // this.age = age;
- // }
- // }
- class C {
- protected num:number;
- constructor(num:number) {
- this.num = num;
- }
- }
- class D extends C {
- sayHello() {
- console.log("你好")
- }
- }
- let c = new C(12);
- console.log(c,'c')
- // c.num = 99;
- let d = new D(23);
- console.log(d)
- // d.num = 88;
- })()
|