Lesson 22 of 55
javascriptClasses – ES6 Syntax, Inheritance, Getters/Setters, static
12 mins
Course progress40%
What you'll learn
Keep these ideas in mind as you work through the lesson.
Lesson 22 of 55
javascript12 mins
Keep these ideas in mind as you work through the lesson.
Class declaration:
class Person {
constructor(name){ this.name = name; }
greet(){ console.log(`Hi, I’m ${this.name}`); }
get upperName(){ return this.name.toUpperCase(); }
set rename(val){ this.name = val; }
static species(){ return 'Homo sapiens'; }
}
Inheritance:
class Employee extends Person {
constructor(name, role){ super(name); this.role = role; }
greet(){ super.greet(); console.log(`My role is ${this.role}`); }
}