我的网站开发技术经验总结 我的网站开发技术经验总结
首页

fangdown

我的网站开发技术经验总结
首页
  • 大前端

    • nodejs

    • git

    • CI

    • 小程序

    • docker

    • Typescript

      • 说说Typescript中命名空间和模块的区别
      • 说说Typescript中的数据类型有哪些
      • 说说什么时候使用枚举类型
      • 说说如何在React项目中使用Typescirpt
      • 说说如何在Vue项目中使用Typescirpt
      • 说说对Typescript中函数的理解
      • 说说对Typescript中接口interface的理解
      • 说说对Typescript中泛型的理解
      • 说说对Typescript中类的理解
        • 是什么
        • 怎么用
          • 继承
          • 修饰符
          • 抽象类
      • 说说对Typescript中高级类型的理解
      • 说说对Typescript的理解
    • webpack

    • 安全

  • 基础

  • 框架

  • 情商

  • 算法

  • 网络

  • 千锤百炼
  • 大前端
  • Typescript
fangdown
2021-09-14
目录

说说对Typescript中类的理解

# 是什么

和 js 中的 class 差不多,但比其丰富,多了修饰符和抽象类

  • 支持类和接口

# 怎么用

  • 字段
  • 构造函数
  • 方法
class Car {
  // 字段
  engine: string;

  // 构造函数
  constructor(engine: string) {
    this.engine = engine;
  }

  // 方法
  disp(): void {
    console.log("发动机为 :   " + this.engine);
  }
}

# 继承

class A {
  move: () => {};
}
class B extends A {
  say: () => {};
}
const b = new B();
b.move();

# 修饰符

  • readonly
  • protected
  • private
  • public
  • static
class A {
  readonly name: string;
  protected age: number;
  private height: number;
  static address: string;
}

# 抽象类

这种类并不能被实例化,通常需要我们创建子类去继承

abstract class Animal {
    abstract makeSound(): void;
    move(): void {
        console.log('roaming the earch...');
    }
}
class Cat extends Animal {
    makeSound() {
        console.log('miao miao')
    }
}

const cat = new Cat()

cat.makeSound() // miao miao
cat.move() // roaming the earch...
#ts
上次更新: 2021/12/19, 18:05:42
说说对Typescript中泛型的理解
说说对Typescript中高级类型的理解

← 说说对Typescript中泛型的理解 说说对Typescript中高级类型的理解→

最近更新
01
多分支修复撞车的问题
05-01
02
如何成为架构师
01-23
03
服务器部署全过程
11-23
更多文章>
Theme by Vdoing | Copyright © 2019-2026 fangdown | 粤ICP备19079809号
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式