三、TS语法

一、类

1. 变量和方法

  • 成员变量
  • 成员静态变量
  • 成员方法
  • 成员静态方法
/*成员变量和成员方法*/
class Person {
    name: string = "erick";
    static readonly age: number = 10;

    say(info: string) {
        console.log(info);
    }

    static work(hour: number) {
        console.log("people work time:" + hour);
    }
}

const person = new Person();
console.log(person.name);
console.log(Person.age);
person.say('hello');
Person.work(4);

2. this 和 constructor

/**/
class Student {
    name: string;
    age: number;

    constructor(name: string, age: number) {
        this.name = name;
        this.age = age;
    }

    say() {
        alert(this.name);
    }

    work() {
        console.log(this);
    }
}

const student = new Student('erick', 10);
student.say();
student.work();

3. 继承

  • 继承
  • super
  • 重写
  • 重载

4. 抽象

  • 抽象类: abstract
  • 接口:interface

5. 封装

// 属性方法,和java稍微不一样
get name(){ return this.name};
set name(name: string){ this.name = name);

6. 泛型

function say<T extends Inter>(a: T): T {};
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值