-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexercise8.html
More file actions
48 lines (43 loc) · 1.4 KB
/
exercise8.html
File metadata and controls
48 lines (43 loc) · 1.4 KB
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>OOP in JS</title>
<script type="text/javascript">
class Employee {
#identity;
#fullname;
#salary;
#iban;
constructor(identity, fullname, salary, iban) {
const self = this;
this.#identity = identity;
this.#fullname = fullname;
this.#salary = salary;
this.#iban = iban;
// this.sayHello = this.sayHello.bind(this);
}
get salary (){ // property
console.log(`get salary(){...} is invoked!`)
return this.#salary;
}
set salary (newSalary){ // property
console.log(`set salary(${newSalary}){...} is invoked!`)
if (newSalary < 8_500)
throw "Salary should be larger than min wage."
this.#salary = newSalary;
}
sayHello = () => {
console.log(self);
console.log(`Hello, ${self.fullname}!`);
}
}
const jack = new Employee("1", "jack bauer", 100_000, "tr1");
const kate = new Employee("2", "kate austen", 200_000, "tr2");
jack.salary = 25_000; // set method is invoked!
console.log(jack.salary);
</script>
</head>
<body>
</body>
</html>