It's really straightforward for me to use private members and use those members inside the class with ECMAScript5, however I don't understand how to get this thing worked with ECMAScript6 using class syntax.
In my code I've tried declaring a property inside constructor function and used the function in a method, but it gets undefined.
class Employee {
constructor(name, empId, workedHours, payment) {
var discount = 0.28;
this.name = name;
this.empId = empId;
this.workedHours = workedHours;
this.payment = payment;
}
monthlyWage() {
return (this.workedHours * this.payment) + (this.workedHours * discount);
}
}
emp1 = new Employee('CooreyMShapher', 12, 89, 900);
So, Is there any way I can use this discount
variable inside every method in the class without defining it as an object attribute?