Skip to content

Commit 5ff57de

Browse files
committed
translate
Translating F.prototype
1 parent 2d5ce73 commit 5ff57de

File tree

1 file changed

+44
-44
lines changed
  • 1-js/08-prototypes/02-function-prototype

1 file changed

+44
-44
lines changed
Lines changed: 44 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
# F.prototype
22

3-
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()`.
44

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.
66

77
```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.
99
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.
1111
```
1212

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.
1414

15-
Here's the example:
15+
Contohnya:
1616

1717
```js run
1818
let animal = {
@@ -32,27 +32,27 @@ let rabbit = new Rabbit("White Rabbit"); // rabbit.__proto__ == animal
3232
alert( rabbit.eats ); // true
3333
```
3434

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`".
3636

37-
That's the resulting picture:
37+
Hasilnya akan seperti gambar dibawah:
3838

3939
![](proto-constructor-animal-rabbit.svg)
4040

41-
On the picture, `"prototype"` is a horizontal arrow, meaning a regular property, and `[[Prototype]]` is vertical, meaning the inheritance of `rabbit` from `animal`.
41+
Dalam gambar, `"prototype"` adalah panah *horizontal*, menandakan properti *regular*, dan `[[Prototype]]` adalah panah vertikal, menandakan pewarisan `rabbit` dari `animal`.
4242

43-
```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.
4545

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.
4747
```
4848
49-
## Default F.prototype, constructor property
49+
## F.prototype bawaan, properti konstruktor
5050
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.
5252
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.
5454
55-
Like this:
55+
Seperti:
5656
5757
```js
5858
function Rabbit() {}
@@ -64,33 +64,33 @@ Rabbit.prototype = { constructor: Rabbit };
6464

6565
![](function-prototype-constructor.svg)
6666

67-
We can check it:
67+
Kita bisa periksa:
6868

6969
```js run
7070
function Rabbit() {}
71-
// by default:
71+
// secara *default*:
7272
// Rabbit.prototype = { constructor: Rabbit }
7373

7474
alert( Rabbit.prototype.constructor == Rabbit ); // true
7575
```
7676

77-
Naturally, if we do nothing, the `constructor` property is available to all rabbits through `[[Prototype]]`:
77+
Secara teknis, jika kita tidak melakukan apapun, properti `constructor` akan tersedia untuk semua "rabbits" melalui `[[Prototype]]`:
7878

7979
```js run
8080
function Rabbit() {}
81-
// by default:
81+
// secara default:
8282
// Rabbit.prototype = { constructor: Rabbit }
8383

84-
let rabbit = new Rabbit(); // inherits from {constructor: Rabbit}
84+
let rabbit = new Rabbit(); // mewarisi dari {constructor: Rabbit}
8585

8686
alert(rabbit.constructor == Rabbit); // true (from prototype)
8787
```
8888

8989
![](rabbit-prototype-constructor.svg)
9090

91-
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.
9292

93-
Like here:
93+
Seperti:
9494

9595
```js run
9696
function Rabbit(name) {
@@ -105,17 +105,17 @@ let rabbit2 = new rabbit.constructor("Black Rabbit");
105105
*/!*
106106
```
107107

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.
109109

110-
But probably the most important thing about `"constructor"` is that...
110+
Tapi mungkin hal yang paling penting tentang `"constructor"` adalah...
111111

112-
**...JavaScript itself does not ensure the right `"constructor"` value.**
112+
**...Javascript sendiri tidak yakin dengan nilai `"constructor"`.**
113113

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.
115115

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"`.
117117

118-
For instance:
118+
Contoh:
119119

120120
```js run
121121
function Rabbit() {}
@@ -129,18 +129,18 @@ alert(rabbit.constructor === Rabbit); // false
129129
*/!*
130130
```
131131

132-
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:
133133

134134
```js
135135
function Rabbit() {}
136136

137-
// Not overwrite Rabbit.prototype totally
138-
// just add to it
137+
// Tidak menimpah Rabbit.prototype selurunya
138+
// hanya menambahkan
139139
Rabbit.prototype.jumps = true
140-
// the default Rabbit.prototype.constructor is preserved
140+
// Rabbit.prototype.constructor bawaan diamankan
141141
```
142142

143-
Or, alternatively, recreate the `constructor` property manually:
143+
Atau, alternatifnya, membuat ulang properti `constructor` secara manual:
144144

145145
```js
146146
Rabbit.prototype = {
@@ -150,26 +150,26 @@ Rabbit.prototype = {
150150
*/!*
151151
};
152152

153-
// now constructor is also correct, because we added it
153+
// sekarang konstruktor tidak berubah, karena kita menambahkan yang baru
154154
```
155155

156156

157-
## Summary
157+
## Ringkasan
158158

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.
160160

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:
162162

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't work.
165-
- The `"prototype"` property only has such a special effect when set on a constructor function, and invoked with `new`.
163+
- Properti `F.prototype` (jangan keliru tentang `[[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`.
166166

167-
On regular objects the `prototype` is nothing special:
167+
Dalam objek biasa `prototype` tidaklah spesial:
168168
```js
169169
let user = {
170170
name: "John",
171-
prototype: "Bla-bla" // no magic at all
171+
prototype: "Bla-bla" // tidak ada yang spesial disini
172172
};
173173
```
174174
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

Comments
 (0)