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. go 可以开发桌面应用

    go 可以开发桌面应用 go 可以开发桌面应用,但并不是很舒适.可以使用的GUI库有:1.goqt,LiteIDE作者出品,Go和QT的绑定,还未发布2.go.uik,纯Go实现的并发UI工具3.wa ...

  2. 请求头header里的contentType为application/json和capplition/x-www-form-urlencoded

    application/x-www-form-urlencoded 最常见的 POST 提交数据的方式了.浏览器的原生 <form> 表单,如果不设置 enctype 属性,那么最终就会以 ...

  3. 单调栈+贪心维护LIS

    普通:O(\(N^2\)) 状态:dp[j]表示,以j结尾的最长的上升子序列 转移:dp[j]=dp[i]+1(if a[j]>a[i] ) 初始化:dp[i]=1 优化(nlogn) solu ...

  4. MyBatis学习总结(16)——Mybatis使用的几个建议

    1.Mapper层参数为Map,由Service层负责重载. Mapper由于机制的问题,不能重载,参数一般设置成Map,但这样会使参数变得模糊,如果想要使代码变得清晰,可以通过service层来实现 ...

  5. POJ——T 3461 Oulipo

    http://poj.org/problem?id=3461 Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 42698   ...

  6. php课程 13-43 mysql的数据结构是什么

    php课程 13-43 mysql的数据结构是什么 一.总结 一句话总结:cs结构,客户端,服务器 1.常用的比较出名的数据库有哪些? SQL数据库(关系型):1.收费:DB2SqlserverOra ...

  7. WebService三大基本元素 SOAP WSDL UDDI

    转自:https://blog.csdn.net/hhooong/article/details/51763128 1.SOAP 即 Simple Object AccessProtocol 也就是简 ...

  8. go reflect 调用方法

    package main import ( "fmt" "reflect" ) type A struct { } func (A) Test() { fmt. ...

  9. 开发板Ping不通虚拟机和主机

    Ubuntu 16.04      win7 笔记本连接学校的无线网 开发板S3c2440与笔记本仅通过COM连接 问题描述: 设置了桥接,主机与虚拟机IP在同一网段后,主机与虚拟机可以Ping,但是 ...

  10. Appium定义接口测试

    1.Appium如何执行 Appium作为一个服务器,python的脚本代码交给Appium服务器,Appium再去与设备交互. desired_cap = {} desired_cap['platf ...