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. $.each(data, function (index, value) { })的用法;json和list<>的互相转换

    在json中常常碰到这样的代码: jquery $.each(data, function (index, value) {    }) 遍历处理data,可以是数组.DOM.json等,取决于直接给 ...

  2. VMwarep挂载镜像及配置本地Yum源

    1.挂载镜像: *. 通过mount命令         linux mount挂载设备(u盘,光盘,iso等 )使用说明 *.  通过VMware的控制页面手工挂载 1.1    打开Vmware软 ...

  3. linux的dhcp4.1.1服务部署

     Centos6.5的dhcp4.1.1服务部署 实施步骤: 1:设置DHCP服务器静态IP和主机名 [root@sw ~]# vim /etc/sysconfig/network-scripts/i ...

  4. iOS报错 -pie can only be used when targeting iOS 4.2 or later

    近期,使用师兄的project时.突然报错之前没发现这个错误.信息例如以下: ld: -pie can only be used when targeting iOS 4.2 or later cla ...

  5. 【开卷故意】JAVA正則表達式模版

    专业既然是机器学习.那工作肯定也是继续和数据打交道,那么问题来了,非常多时候推荐算法和数据挖掘算法都是现成可用的,平台初建,重点还在数据过滤和抽取.如何高效的抽取数据? 利用往常算法比赛中经常使用的字 ...

  6. 玩转Bash脚本:选择结构之case

    总第5篇 之前,我们谈到了if. 这次我们来谈还有一种选择结构--case. case与if if用于选择的条件,不是非常多的情况,假设选择的条件太多.一系列的if.elif,.也是醉了. 没错,ca ...

  7. JavaScript--数据结构之栈

    4.1栈是一种高效的数据结构,是一种特殊的列表.栈内元素只能通过列表的一端访问,也就称为栈顶.后入的先出的操作.Last in First out.所以他的访问每次是访问到栈顶的元素,要想访问其余的元 ...

  8. Flask项目之手机端租房网站的实战开发(十三)

    说明:该篇博客是博主一字一码编写的,实属不易,请尊重原创,谢谢大家! 接着上一篇博客继续往下写 :https://blog.csdn.net/qq_41782425/article/details/8 ...

  9. spring+mybatis+Atomikos JTA事务配置说明

    一.概览 Atomikos是一个公司名字,旗下最著名的莫过于其Atomikos的事务管理器产品.产品分两个:一个是开源的TransactionEssentials,一个是商业的ExtremeTrans ...

  10. Akka边学边写(4)-- MiniRPG

    前面几篇文章用Akka写了HelloWorld和EchoServer,为了更进一步学习Akka,本文将会实现一个非常小的RPG游戏server:MiniRPG. 游戏逻辑 由于是迷你RPG,所以逻辑非 ...