-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path50-Setter_Getter.html
49 lines (36 loc) · 1009 Bytes
/
50-Setter_Getter.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Setter dan Getter</title>
</head>
<body>
<script>
// Setter dan getter adalah fiture untuk merubah method object menjadi properti.
// getter untuk mengambil value
// setter untuk merubah value
const person = {
firsName: 'Eko',
lastName: 'Khanedy',
get fullName() {
return `${this.firsName} ${this.lastName}`;
},
set fullName(value) {
const array = value.split(" ");
this.firsName = array[0];
this.lastName = array[1];
}
}
console.log(person.fullName);
console.table(person);
person.fullName = "Wandy Azami";
console.log(person.fullName);
console.table(person);
person.fullName = "Joe Swat";
console.log(person.fullName);
console.table(person);
</script>
</body>
</html>