0

Problem:

when i am calling a programmer child class's method (overridden method) by using programmer class's object its calling parent Employee class's method.

What i've tried:

parent class's method is a arrow function but child classs's method is a normal function.If i make parent class's method as normal method it solves the problem but my question is why did this happen?

Can someone please explain this behaviour ?

here's the code:

class Employee {
    constructor(name){
        this.name = name;
    } 
    login = ()=>{
        console.log("Employee "+this.name+" logged in...");
    }
}

class Programmer extends Employee{
    login(){
        console.log("Programmer "+this.name+" logged in...");
    }
}

let emp = new Programmer("Ankur");
emp.login();
  • 1
    Or https://stackoverflow.com/q/31095710/3001761, https://stackoverflow.com/q/56055658/3001761, ... Please do basic research before asking. – jonrsharpe Mar 29 '23 at 14:01

0 Answers0