Typescript classes make inheritance much easier to write and understand. In this lesson we look into how to set up inheritance with Typescript classes, extends and super.

class ComicBookCharacter (
constructor{
public alias: string, public health: number , public strength: number,
protected secretIdentity: string
) {}
} class SuperVillain extends ComicBookCharacter {
flaws = ["hubris", "always explains evil plan"]; constructor(a, b, c, d) {
console.log('${this.alias} eats kittens!!!');
super(a, b, c, d);
}
}

To review, we can set up inheritance with the extends keyword. The protected access modifier can't be accessed outside of a class just like the private access modifier, but it can be accessed in derived classes.

If you don't define a constructor, the derived class will use the base class's constructor. If you do define the constructor in a derived class, super must be called before anything else can happen.

[TypeScript] Sharing Class Behavior with Inheritance in TypeScript的更多相关文章

  1. [TypeScript] Distinguishing between types of Strings in TypeScript

    In JavaScript, many libraries use string arguments to change behavior. In this lesson we learn how T ...

  2. [TypeScript] Define Custom Type Guard Functions in TypeScript

    One aspect of control flow based type analysis is that the TypeScript compiler narrows the type of a ...

  3. [TypeScript] Union Types and Type Aliases in TypeScript

    Sometimes we want our function arguments to be able to accept more than 1 type; e.g. a string or an ...

  4. [TypeScript] Using Assertion to Convert Types in TypeScript

    Sometimes the compiler needs help figuring out a type. In this lesson we learn how to help out the c ...

  5. [TypeScript] Using Interfaces to Describe Types in TypeScript

    It’s easy to pass the wrong value to a function. Typescript interfaces are great because they catch ...

  6. [TypeScript] Catch unsafe use of "this" in TypeScript functions

    this is probably the most tricky thing to use in JavaScript and therefore TypeScript. Fortunately th ...

  7. [TypeScript ] Using the Null Coalescing operator with TypeScript 3.7

    The postshows you how to use the null coalescing operator (??) instead of logical or (||) to set def ...

  8. 我要涨知识 —— TypeScript 常见面试题(一)

    1.ts 中的 any 和 unknown 有什么区别? unknown 和 any 的主要区别是 unknown 类型会更加严格:在对 unknown 类型的值执行大多数操作之前,我们必须进行某种形 ...

  9. 转职成为TypeScript程序员的参考手册

    写在前面 作者并没有任何可以作为背书的履历来证明自己写作这份手册的分量. 其内容大都来自于TypeScript官方资料或者搜索引擎获得,期间掺杂少量作者的私见,并会标明. 大部分内容来自于http:/ ...

随机推荐

  1. vue methods 方法中 方法 调用 另一个方法。

    vue在同一个组件内: methods中的一个方法调用methods中的另外一个方法. 可以在调用的时候 this.$options.methods.test(); this.$options.met ...

  2. Windows共享上网的详细设置

    作者:朱金灿 来源:http://blog.csdn.net/clever101 在Windows环境下在A和B在同一个局域网上,A机子可以上网,B机子可以通过A机子可以通过设置的网络共享来上网.其中 ...

  3. javafx virtual keyboard

    public class EffectTest extends Application { @Override public void start(final Stage stage) { final ...

  4. 【Uva 1543】Telescope

    [Link]: [Description] 给你一个圆和圆周上的n(3≤n≤40)个不同点.请选择其中的m(3≤m≤n)个,按照在圆 周上的顺序连成一个m边形,使得它的面积最大. [Solution] ...

  5. [React] Define defaultProps and PropTypes as static methods in class component

    class Toggle extends Component { static propTypes = { defaultOn: PropTypes.bool, on: PropTypes.bool, ...

  6. 【试水CAS-4.0.3】第07节_CASclient配置单点登录

    完整版见https://jadyer.github.io/2015/07/26/sso-cas-client-login/ 本文源代码下载:http://download.csdn.net/detai ...

  7. error while loading shared libraries: libpcre.so.0的解决办法

    error while loading shared libraries: libpcre.so.0的解决办法 http://blog.csdn.net/xjkwq1qq/article/detail ...

  8. 转:Java的一道面试题----静态变量初始化过程

    public class Test{ private static Test tester = new Test(); //step 1 private static int count1; //st ...

  9. 2.2 Consumer API官网剖析(博主推荐)

    不多说,直接上干货! 一切来源于官网 http://kafka.apache.org/documentation/ 2.2 Consumer API 2.2.消费者API 随着0..0版本,我们已经增 ...

  10. 洛谷P3954 成绩【民间数据】

    题目背景 数据已修复 题目描述 牛牛最近学习了C++入门课程,这门课程的总成绩计算方法是: 总成绩=作业成绩×20%+小测成绩×30%+期末考试成绩×50% 牛牛想知道,这门课程自己最终能得到多少分. ...