Skip to content

Commit 461c22a

Browse files
committed
event 03: article.md - 60%
1 parent 96fec5f commit 461c22a

File tree

1 file changed

+22
-22
lines changed

1 file changed

+22
-22
lines changed

Diff for: 2-ui/2-events/03-event-delegation/article.md

+22-22
Original file line numberDiff line numberDiff line change
@@ -107,25 +107,25 @@ Penjelasan:
107107

108108
Hasilnya, kita memiliki kode yang cepat, efisien dalam memberikan highlight, yang tidak peduli terhadap jumlah dari elemen `<td>` pada sebuah tabel.
109109

110-
## Delegation example: actions in markup
110+
## Contoh Delegasi: tindakan dalam markup
111111

112-
There are other uses for event delegation.
112+
Ada kegunaan lain untuk delegasi acara.
113113

114-
Let's say, we want to make a menu with buttons "Save", "Load", "Search" and so on. And there's an object with methods `save`, `load`, `search`... How to match them?
114+
Bayangkan, kita mau membuat sebuah menu dengan tombol "Simpan", "Muat", "Cari" dan seterusnya. Dan ada sebuah objek dengan metode `simpan`, `muat`, `cari`... Bagaimana cara untuk menyamakan mereka?
115115

116-
The first idea may be to assign a separate handler to each button. But there's a more elegant solution. We can add a handler for the whole menu and `data-action` attributes for buttons that has the method to call:
116+
Ide pertama yaitu dengan mengatur penangan (_handler_) berbeda pada setiap tombol, Tapi ada solusi yang lebih elegan. Kita bisa menambahkan sebuah penangan (_handler_) untuk seseluruhan menu dan menambahkan atribut `data-action` untuk tombol yang bisa memanggil/memiliki sebuah metode:
117117

118118
```html
119-
<button *!*data-action="save"*/!*>Click to Save</button>
119+
<button *!*data-action="save"*/!*>Klik untuk simpan</button>
120120
```
121121

122-
The handler reads the attribute and executes the method. Take a look at the working example:
122+
Penangan (_handler_) membaca atribut dan mengeksekusi metode yang sama dengan atribut. Coba lihat contohnya:
123123

124124
```html autorun height=60 run untrusted
125125
<div id="menu">
126-
<button data-action="save">Save</button>
127-
<button data-action="load">Load</button>
128-
<button data-action="search">Search</button>
126+
<button data-action="save">Simpan</button>
127+
<button data-action="load">Muat</button>
128+
<button data-action="search">Cari</button>
129129
</div>
130130

131131
<script>
@@ -136,15 +136,15 @@ The handler reads the attribute and executes the method. Take a look at the work
136136
}
137137
138138
save() {
139-
alert('saving');
139+
alert('Menyimpan');
140140
}
141141
142142
load() {
143-
alert('loading');
143+
alert('Memuat');
144144
}
145145
146146
search() {
147-
alert('searching');
147+
alert('Mencari');
148148
}
149149
150150
onClick(event) {
@@ -161,24 +161,24 @@ The handler reads the attribute and executes the method. Take a look at the work
161161
</script>
162162
```
163163

164-
Please note that `this.onClick` is bound to `this` in `(*)`. That's important, because otherwise `this` inside it would reference the DOM element (`elem`), not the `Menu` object, and `this[action]` would not be what we need.
164+
Harap dicatat bahwa `this.onClick` terikat pada `this` di `(*)`. Itu penting, karena jika tidak `this` didalamnya akan menyimpan referensi ke DOM elemen (`elem`), buka ke objek `Menu`, dan `this[action]` tidak akan seperti yang kita inginkan.
165165

166-
So, what advantages does delegation give us here?
166+
Jadi,apakah keuntuk yang diberikan delegasi kepada kita disini?
167167

168168
```compare
169-
+ We don't need to write the code to assign a handler to each button. Just make a method and put it in the markup.
170-
+ The HTML structure is flexible, we can add/remove buttons at any time.
169+
+ Kita teidak perlu lagi menulis kode untuk mengatur penangan (_handler_) untuk setiap tombol. Kita hanya perlu membuat sebuah metode dan menaruh markup didalamnya.
170+
+ Struktur HTML menjadi fleksible, dan kita bisa menambah/menghapus tombol kapanpun kita mau.
171171
```
172172

173-
We could also use classes `.action-save`, `.action-load`, but an attribute `data-action` is better semantically. And we can use it in CSS rules too.
173+
Kita juga bisa menggunakan _class_ `.action-save`, `action-load`, tapi sebuah atribut `data-action` lebih baik secara semantik. Dan kita bisa gunakan itu pada aturan CSS juga.
174174

175-
## The "behavior" pattern
175+
## Perilaku pola
176176

177-
We can also use event delegation to add "behaviors" to elements *declaratively*, with special attributes and classes.
177+
Kita juga bisa menggunakan delegasi peristiwa untuk menambahkan 'perilaku' kepada elemen secara deklarasi, dengan atribut khusus dan _class_.
178178

179-
The pattern has two parts:
180-
1. We add a custom attribute to an element that describes its behavior.
181-
2. A document-wide handler tracks events, and if an event happens on an attributed element -- performs the action.
179+
Pola memiliki 2 bagian:
180+
1. Kita tambahkan sebuah atribut khusus ke sebuah elemen yang menjelaskan perilakunya.
181+
2. Penangan dokumen secara umum untuk melacak peristiwa, dan jika sebuah peristiwa terjadi pada elemen yang memiliki atribut khusus -- jalankan sebuah proses.
182182

183183
### Behavior: Counter
184184

0 commit comments

Comments
 (0)