123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- "use strict";
- // 属性 封装:令属性更安全
- (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 {
- constructor(num) {
- 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;
- })();
|