Classes
class Person {
greet() {
console.log('Hello!!');
}
}
const alan = new Person(); // This is instances as an object of type person
alan.greet();
const laura = new Person(); // This is also an object of type person
laura.greet(); // Can do the same actionsclass Person {
constructor(name) { // The constructor receives a parameter
this._name = name; // The this keyword must be used
this._behavior = 50;
}
checkBehavior() {
console.log(this._behavior);
}
}
const alan = new Person('Alan'); // We pass a value to the constructor to be set
alan.checkBehavior();Inheritance
Last updated