super method depreciation on js code example
Example 1: extended class call method from super in javascript
class Person {
constructor(name, age) {
this.name = name;
this.age = age;
}
greet() {
console.log(`Hi, all my name is ${this.name}`);
}
}
class Employee extends Person {
constructor(name, age, employer) {
super(name, age);
this.employer = employer;
}
greeting() {
super.greet();
console.log(`I'm working at ${this.employer}`);
}
}
let Steve = new Employee('Xman', 25 , 'Skynet');
Steve;
Steve.greeting();
Example 2: javascript super
class Parent {
constructor() {}
method() {}
}
class Child extends Parent {
constructor() {
super()
super.method()
}
}