OOP Inheritance
Lesson Objectives
Make a class inherit attributes from a "parent class"
class Person {
constructor (name, age, eyes, hair, lovesCats = true, lovesDogs) {
this.legs = 2;
this.arms = 2;
this.name = name;
this.age = age;
this.eyes = eyes;
this.hair = hair;
this.lovesCats = lovesCats;
this.lovesDogs = lovesDogs || true;
}
greet (otherPerson) {
console.log('hi ' + otherPerson + '!');
}
classyGreeting (otherClassyPerson) {
console.log('Howdy ' + otherClassyPerson.name + '!');
}
setHair (hairColor) {
this.hair = hairColor;
}
walk () {
console.log('I hate when my Segway is in the shop.');
}
}
const supermanPerson = new Person('Clark Kent', 30, 'blue', 'black')
console.log(supermanPerson);Last updated