You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Remember, new objects can be created with a constructor function, like`new F()`.
3
+
Ingat ketika objek baru bisa dibuat dengan menggunakan fungsi konstruktor seperti`new F()`.
4
4
5
-
If`F.prototype`is an object, then the`new`operator uses it to set `[[Prototype]]`for the new object.
5
+
Jika`F.prototype`adalah sebuah objek, maka operator`new`menggunakannya untuk menyetel `[[Prototype]]`untuk objek barunya.
6
6
7
7
```smart
8
-
JavaScript had prototypal inheritance from the beginning. It was one of the core features of the language.
8
+
Javascript memiliki pewarisan *prototype* dari awal. Itu adalah salah satu fitur utama dari bahasanya.
9
9
10
-
But in the old times, there was no direct access to it. The only thing that worked reliably was a `"prototype"` property of the constructor function, described in this chapter. So there are many scripts that still use it.
10
+
Tapi dimasa lalu, hal itu tidak memiliki akses langsung. Hal yang dapat diandalkan adalah properti `"prototype"` dari fungsi konstruktor, yang akan dijelaskan didalam bab ini. Jadi masih banyak skrip yang masih menggunakannya.
11
11
```
12
12
13
-
Please note that `F.prototype`here means a regular property named`"prototype"`on`F`. It sounds something similar to the term "prototype", but here we really mean a regular property with this name.
13
+
Catat bahwa `F.prototype`disini berarti properti biasa yang bernama`"prototype"`didalam`F`. Terdengar seperti istilah "prototype", tapi disini kita menunjuk properti biasa dengan nama itu.
14
14
15
-
Here's the example:
15
+
Contohnya:
16
16
17
17
```js run
18
18
let animal = {
@@ -32,27 +32,27 @@ let rabbit = new Rabbit("White Rabbit"); // rabbit.__proto__ == animal
32
32
alert( rabbit.eats ); // true
33
33
```
34
34
35
-
Setting`Rabbit.prototype = animal`literally states the following: "When a`new Rabbit`is created, assign its `[[Prototype]]` to`animal`".
35
+
Menyetel`Rabbit.prototype = animal`secara literal kita mengartikan: "Ketika sebuah`new Rabbit`dibuat, itu akan memasukan `[[Prototype]]`nya ke`animal`".
36
36
37
-
That's the resulting picture:
37
+
Hasilnya akan seperti gambar dibawah:
38
38
39
39

40
40
41
-
On the picture, `"prototype"`is a horizontal arrow, meaning a regular property, and`[[Prototype]]`is vertical, meaning the inheritance of `rabbit`from`animal`.
```smart header="`F.prototype`only used at`new F` time"
44
-
`F.prototype`property is only used when `new F`is called, it assigns`[[Prototype]]`of the new object.
43
+
```smart header="`F.prototype`hanya digunakan pada`new F`"
44
+
Properti `F.prototype`hanya digunakan ketika `new F`dipanggil, itu memasukan`[[Prototype]]`dari objek barunya.
45
45
46
-
If, after the creation, `F.prototype`property changes (`F.prototype = <another object>`), then new objects created by `new F`will have another object as`[[Prototype]]`, but already existing objects keep the old one.
46
+
Jika, setelah pembuatan, properti `F.prototype`berubah (`F.prototype = <objek lain>`), maka objek baru yang dibuat menggunakan `new F`akan memiliki objek lain sebagai`[[Prototype]]`, tapi objek yang sudah ada akan menyimpan yang lama.
47
47
```
48
48
49
-
## Default F.prototype, constructor property
49
+
## F.prototype bawaan, properti konstruktor
50
50
51
-
Every function has the `"prototype"` property even if we don't supply it.
51
+
Setiap fungsi memiliki properti `"prototype"` bahkan jika kita tidak memberikannya.
52
52
53
-
The default `"prototype"` is an object with the only property `constructor` that points back to the function itself.
53
+
`"prototype"` bawaan adalah sebuah objek dengan properti `constructor` yang menunjuk balik pada fungsinya sendiri.
We can use `constructor`property to create a new object using the same constructor as the existing one.
91
+
Kita bisa menggunakan properti `constructor`untuk membuat objek baru menggunakan konstruktor yang sama seperti yang sudah ada.
92
92
93
-
Like here:
93
+
Seperti:
94
94
95
95
```js run
96
96
functionRabbit(name) {
@@ -105,17 +105,17 @@ let rabbit2 = new rabbit.constructor("Black Rabbit");
105
105
*/!*
106
106
```
107
107
108
-
That's handy when we have an object, don't know which constructor was used for it (e.g. it comes from a 3rd party library), and we need to create another one of the same kind.
108
+
Hal itu akan mudak ketika kita memiliki sebuah objek, tidak tahu konstruktor yang mana yang menggunakannya (mis. ketika datang dari *library* pihak ketiga), dan kita butuh membuat satu lagi dengan bentuk yang sama.
109
109
110
-
But probably the most important thing about`"constructor"`is that...
110
+
Tapi mungkin hal yang paling penting tentang`"constructor"`adalah...
111
111
112
-
**...JavaScript itself does not ensure the right `"constructor"` value.**
112
+
**...Javascript sendiri tidak yakin dengan nilai `"constructor"`.**
113
113
114
-
Yes, it exists in the default`"prototype"` for functions, but that's all. What happens with it later -- is totally on us.
114
+
Ya, terdapat nilai untuk fungsi bawaan`"prototype"`, tapi hanya itu. Apa yang terjadi setelahnya -- semuanya bergantung pada kita.
115
115
116
-
In particular, if we replace the default prototype as a whole, then there will be no`"constructor"` in it.
116
+
Khususnya, jika kita mengganti seluruh prototype bawaannya, maka disana tidak akan terdapat`"constructor"`.
So, to keep the right `"constructor"`we can choose to add/remove properties to the default`"prototype"`instead of overwriting it as a whole:
132
+
Jadi, untuk menyimpan `"constructor"`dengan benar kita bisa memilih untuk menambahkan/menghapus properti menjadi`"prototype"`bawaan daripada menimpahnya dengan yang baru:
133
133
134
134
```js
135
135
functionRabbit() {}
136
136
137
-
//Not overwrite Rabbit.prototype totally
138
-
//just add to it
137
+
//Tidak menimpah Rabbit.prototype selurunya
138
+
//hanya menambahkan
139
139
Rabbit.prototype.jumps=true
140
-
//the default Rabbit.prototype.constructor is preserved
140
+
// Rabbit.prototype.constructor bawaan diamankan
141
141
```
142
142
143
-
Or, alternatively, recreate the `constructor`property manually:
143
+
Atau, alternatifnya, membuat ulang properti `constructor`secara manual:
144
144
145
145
```js
146
146
Rabbit.prototype= {
@@ -150,26 +150,26 @@ Rabbit.prototype = {
150
150
*/!*
151
151
};
152
152
153
-
//now constructor is also correct, because we added it
153
+
//sekarang konstruktor tidak berubah, karena kita menambahkan yang baru
154
154
```
155
155
156
156
157
-
## Summary
157
+
## Ringkasan
158
158
159
-
In this chapter we briefly described the way of setting a `[[Prototype]]` for objects created via a constructor function. Later we'll see more advanced programming patterns that rely on it.
159
+
Didalam chapter ini kita secara jelas mendeskripsikan cara untuk menyetel `[[Prototype]]` untuk objek yang dibuat dengan menggunakan fungsi konstruktor. Nanti kita akan melihat lebih banyak alur *programming* lanjutan yang akan menggunakannya.
160
160
161
-
Everything is quite simple, just a few notes to make things clear:
161
+
Semuanya cukup simpel, hanya tinggal mengingat beberapa langkah untuk membuat lebih jelas:
162
162
163
-
- The `F.prototype` property (don't mistake it for `[[Prototype]]`) sets `[[Prototype]]` of new objects when `new F()` is called.
164
-
- The value of `F.prototype` should be either an object or `null`: other values won'twork.
165
-
-The`"prototype"`propertyonlyhassuchaspecialeffectwhensetonaconstructor function, and invoked with `new`.
163
+
- Properti `F.prototype` (jangankelirutentang`[[Prototype]]`) menyetel `[[Prototype]]` dari objek baru ketika `new F()` dipanggil.
164
+
- Nilai dari `F.prototype` harusnya antara sebuah objek atau `null`: nilai lainnya tidak akan bekerja.
165
+
- Properti `"prototype"` hanya memiliki efek spesial ketika menyetel fungsi konstruktor, dan dipanggil dengan `new`.
166
166
167
-
On regular objects the `prototype` is nothing special:
167
+
Dalam objek biasa `prototype` tidaklah spesial:
168
168
```js
169
169
let user = {
170
170
name:"John",
171
-
prototype: "Bla-bla" //no magic at all
171
+
prototype:"Bla-bla"//tidak ada yang spesial disini
172
172
};
173
173
```
174
174
175
-
By default all functions have `F.prototype = { constructor: F }`, so we can get the constructor of an object by accessing its `"constructor"` property.
175
+
Secara teknis semua fungsi memiliki`F.prototype= { constructor: F }`, jadi kita bisa mendapatkan konstruktor dari sebuah objek dengan mengakses properti `"constructor"` miliknya sendiri.
0 commit comments