June 2016
Beginner to intermediate
292 pages
6h 8m
English
The class construct introduced by the ECMAScript 6 specifications also brings a new way to define inheritance. Using a syntax similar to most common classical Object-Oriented Programming languages, we can make a class inherit from another one. Let's take the previous example of person and developer and rewrite it using classes:
class Person {
constructor(name, surname) {
this.name = name;
this.surname = surname;
}
}
class Developer extends Person {
constructor(name, surname, knownLanguage) {
super(name, surname);
this. knownLanguage = knownLanguage;
}
}
In this example, we have highlighted the relevant parts of inheritance. As we can see, the class Developer inherits from the class Person using the extends keyword. Moreover, in ...
Read now
Unlock full access