I have done some tasks for my job, I have done all of them. But I have some problems, it doesn't work as it supposed to. When I'm trying to add a new user for Customer class, for example:
var user3 = new Customer ("Sergiu", "Tataru");
And when I access user3, I receive:
lastname: undefined
Why so?
See the result to understand what I mean
The tasks that I have done:
- Use a Person class and extend it for the Employee and Customer classes.
- The Person object has a private name property and a getter method for the name.
- The Employee class has two private properties hire date and salary. It also has getter methods for the two properties.
- The Customer class has a private contract number property and a getter for the contract number.
The code:
//4)Create a Person class
class Person{
constructor(firstName, lastName) {
this.firstname = firstName;
this.lastname = lastName;
var _name = name;// create a private name property for the Person class
// create a getter method for the name for the Person class
this.getName = function () {
return _name;
};
this.getFullName = function() {
return this.firstname+ " " + this.lastname;
};
}
}
// extend Person class for the Employee and Customer classes.
class Employee extends Person {
constructor(hireDate, salary){
super(hireDate, salary);
var _hiredate = hireDate; // create a private property hire date for Employee class
var _salary = salary; // create a private property salary for Employee class
// create a getter method for the hire date s
this.getHireDate = function(){
return _hiredate;
};
// create a getter method for the salary
this.getSalary = function(){ //varianta alternativa: Employee.prototype.getSalary = function(){
return _salary;
};
}
}
class Customer extends Person {
constructor(contractNumber){
super(contractNumber);
var _contractNumber = contractNumber; // create a private contract number for Customer class
//create a getter for the contract number.
this.getcontractNumber = function(){
return _contractNumber;
};
};
}