-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunction-arrow-in-object.html
86 lines (76 loc) · 2.57 KB
/
function-arrow-in-object.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
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
<!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>Arrow Function di Object</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
padding: 2rem;
}
p {
padding: .5rem 0;
}
div {
width: 100%;
height: 100vh;
background-color: rgb(0, 195, 255);
font-weight: 800;
font-size: 2rem;
font-family: sans-serif;
text-transform: uppercase;
display: flex;
justify-content: center;
align-items: center;
color: #0e0e0e;
}
</style>
</head>
<body>
<script>
/*
## Arrow Function di Object
● Sebelumnya kita sudah bahas tentang Arrow Function
● Arrow Function juga bisa kita gunakan di sebagai Object Method
● Namun perlu diketahui, Arrow Function tidak bisa digunakan untuk mengakses arguments object, function generator, kata kunci this dan kata kunci super (dibahas di materi JavaScript Object Oriented Programming)
● Jadi pastikan gunakan Arrow Function hanya memang ketika kita tidak butuh fitur-fitur diatas
*/
document.writeln(`<div>Press f12</div>`);
// =====Kode : Arrow Function di Object Method=====
document.writeln(`<p>=====Arrow Function di Object Method=====</p>`);
const person = {
name: "Fauzan",
sayHello: (name) => {
console.info(`Hello ${name}`);
}
};
person.sayHello("Budi");
// =====Kode : this di Arrow Function Object=====
document.writeln(`<p>=====this di Arrow Function Object=====</p>`);
const personTwo = {
name: "Fauzan",
sayHelloTwo: (name) => {
console.info(this);
console.info(`Hello ${name}, My name is ${this.name}`);
}
};
personTwo.sayHelloTwo("Budi");
// =====Kode : this di Arrow Function Object=====
document.writeln(`<p>=====this di Arrow Function Object=====</p>`);
const personThree = {
name: "Fauzan",
sayHelloTwo: (name) => {
console.info(this);
console.info(`Hello ${name}, My name is ${this.name}`);
}
};
personThree.sayHelloTwo("Budi");
</script>
</body>
</html>