Inheritance – Overloading - TypeScript - JavaScript's Superset
☰Fullscreen
Table of Content:
JavaScript uses prototypical inheritance instead of classical inheritance.
TypeScript allows us to inherit from existing classes according to need. Here is a code snippet to explain:
class Cube {
length: number;
constructor(length : number) {
this.length = length;
}
}
class Physics extends Cube {
color: string;
constructor(length: number, color: string) {
super(length);
this.color = color;
}
}
var obj = new Physics(10, "yellow");