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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.