对我来说,使用私有成员并使用 ECMAScript5 在类中使用这些成员非常简单,但是我不明白如何使用类语法让这个东西与 ECMAScript6 一起工作。
在我的代码中,我尝试在构造函数中声明一个属性并在方法中使用该函数,但它未定义。
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);
那么,有什么方法可以discount
在类中的每个方法中使用这个变量而不将它定义为对象属性?