Prototypal inheritance

You might be wondering how the extends keyword works. Let's create a new TypeScript class, which inherits from the Person class, to understand it:

class SuperHero extends Person {    public superpower: string;    public constructor(        name: string,        surname: string,        superpower: string    ) {        super(name, surname);        this.superpower = superpower;    }    public userSuperPower() {        return 'I'm using my ${this.superpower}';    }}

The preceding class is named SuperHero and extends the Person class. It has one additional attribute (superpower) and method (useSuperPower). 

We need to compile the previous code snippet into JavaScript code so we can examine how inheritance is implemented at runtime. The compiler will generate a polyfill function named ...

Get Hands-On Functional Programming with TypeScript now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.