@kenanhancer/

GoldAwkwardPhp

JavaScript

No description

fork
loading
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
let Person = function(personId, firstName, lastName, age, gender) {
  this.personId = personId;
  this.firstName = firstName;
  this.lastName = lastName;
  this.age = age;
  this.gender = gender;
};

Person.prototype.getFullName = function() {
  return `${this.firstName} ${this.lastName}`;
};

Person.prototype.greet = function() {
  return `Hello ${this.getFullName()}`;
};

let Employee = function() {
  let args = Array.prototype.slice.call(arguments);

  let _title = args[5];
  let _salary = args[6];

  if (_title) {
    this.title = _title;
  }

  if (_salary) {
    this.salary = _salary;
  }

  this.taxRate = 0.14;

  Person.apply(this, args);
};

//INHERITANCE
Employee.prototype = Object.create(Person.prototype);
Employee.prototype.constructor = Employee;

Employee.prototype.calculateGrossSalary = function() {
  let netSalary = this.calculateNetSalary();

  return netSalary * (1 + this.taxRate);
};

Employee.prototype.calculateNetSalary = function() {
  return this.salary * 12;
};

let Manager = function() {
  let args = Array.prototype.slice.call(arguments);

  Employee.apply(this, args);

  this.taxRate = 0.21;
};

//INHERITANCE
Manager.prototype = Object.create(Employee.prototype);
Manager.prototype.constructor = Manager;

//OVERRIDE
Manager.prototype.greet = function() {
  let _greet = Employee.prototype.greet.call(this);
  return `${_greet}, Welcome!`;
};

let employee1 = new Employee(1, "Kenan", "Hancer", 33, "MALE", "WORKER", 1000);

let manager1 = new Manager(2, "Enes", "Demir", 40, "MALE", "MANAGER", 5000);

console.log(employee1);

console.log(employee1.getFullName());

console.log(employee1.greet());

console.log(employee1.calculateNetSalary());

console.log(employee1.calculateGrossSalary());

console.log();

console.log(manager1);

console.log(manager1.getFullName());

console.log(manager1.greet());

console.log(manager1.calculateNetSalary());

console.log(manager1.calculateGrossSalary());
Native Browser JavaScript