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
The assignment to `Rabbit.prototype`sets up `[[Prototype]]`for new objects, but it does not affect the existing ones.
6
+
Memasukan ke `Rabbit.prototype`menyetel `[[Prototype]]`untuk objek baru, tapi itu tidak memberikan efek pada yang sudah ada.
7
7
8
8
2.`false`.
9
9
10
-
Objects are assigned by reference. The object from `Rabbit.prototype`is not duplicated, it's still a single object referenced both by`Rabbit.prototype`and by the `[[Prototype]]`of`rabbit`.
10
+
Objek yang dimasukan dengan menggunakan referensi. Objek dari `Rabbit.prototype`bukanlah di duplikasi, itu masih tetap objek tunggal yang direferensikan dari`Rabbit.prototype`dan dari `[[Prototype]]`dari`rabbit`.
11
11
12
-
So when we change its content through one reference, it is visible through the other one.
12
+
Jadi ketika kita mengubah kontennya melalui satu referensi, itu masih terlihat melalui yang lainnya.
13
13
14
14
3.`true`.
15
15
16
-
All `delete`operations are applied directly to the object. Here`delete rabbit.eats`tries to remove `eats`property from `rabbit`, but it doesn't have it. So the operation won't have any effect.
16
+
Semua operasi `delete`diterapkan langsung ke objeknya. Disini`delete rabbit.eats`mencoba untuk menghapus properti `eats`dari `rabbit`, tapi itu tidak memilikinya. Jadi operasinya tidak akan menghasilkan efek apapun.
17
17
18
18
4.`undefined`.
19
19
20
-
The property `eats`is deleted from the prototype, it doesn't exist any more.
20
+
Properti `eats`dihapus dari *prototype*, itu tidak akan ada lagi.
We can use such approach if we are sure that `"constructor"`property has the correct value.
1
+
Kita bisa menggunakan pendekatan jika kita yakin properti `"constructor"`memiliki nilai yang benar.
2
2
3
-
For instance, if we don't touch the default `"prototype"`, then this code works for sure:
3
+
Contoh, kita tidak ingin menyentuh `"prototype"` bawaan, maka kode ini akan berjalan dengan semestinya:
4
4
5
5
```js run
6
6
functionUser(name) {
@@ -10,14 +10,14 @@ function User(name) {
10
10
let user =newUser('John');
11
11
let user2 =newuser.constructor('Pete');
12
12
13
-
alert( user2.name ); // Pete (worked!)
13
+
alert( user2.name ); // Pete (bekerja!)
14
14
```
15
15
16
-
It worked, because`User.prototype.constructor == User`.
16
+
Kode diatas bekerja karena`User.prototype.constructor == User`.
17
17
18
-
..But if someone, so to speak, overwrites `User.prototype`and forgets to recreate `constructor`to reference `User`, then it would fail.
18
+
Tapi jika seseorang, menimpah `User.prototype`dan lupa untuk membuat ulang `constructor`untuk `User`, maka akan membuat kegagalan.
19
19
20
-
For instance:
20
+
Contoh:
21
21
22
22
```js run
23
23
functionUser(name) {
@@ -33,12 +33,12 @@ let user2 = new user.constructor('Pete');
33
33
alert( user2.name ); // undefined
34
34
```
35
35
36
-
Why`user2.name`is`undefined`?
36
+
Kenapa`user2.name`menghasilan`undefined`?
37
37
38
-
Here's how`new user.constructor('Pete')`works:
38
+
Ini bagaimana`new user.constructor('Pete')`bekerja:
39
39
40
-
1.First, it looks for`constructor`in`user`. Nothing.
41
-
2.Then it follows the prototype chain. The prototype of `user`is`User.prototype`, and it also has nothing.
42
-
3.The value of `User.prototype`is a plain object`{}`, its prototype is `Object.prototype`. And there is`Object.prototype.constructor == Object`. So it is used.
40
+
1.Pertama, itu akan mencari`constructor`didalam`user`. Tidak ditemukan.
41
+
2.Lalu akan mengukuti rantai *prototype*. *Prototype* dari `user`adalah`User.prototype`, dan itu juga tidak memilikinya.
42
+
3.Nilai dari `User.prototype`adalah sebuah objek polos`{}`, prototypenya adalah `Object.prototype`. dan disana terdapat`Object.prototype.constructor == Object`. Jadi itu digunakan.
43
43
44
-
At the end, we have `let user2 = new Object('Pete')`. The built-in `Object`constructor ignores arguments, it always creates an empty object, similar to`let user2 = {}`, that's what we have in`user2` after all.
44
+
Pada akhirnya kita memiliki `let user2 = new Object('Pete')`. Konstruktor `Object`bawaan menghiraukan argumen, itu selalu menciptakan objek kosong, sama seperti`let user2 = {}`, itulah yang kita punya didalam`user2`.
Imagine, we have an arbitrary object `obj`, created by a constructor function -- we don't know which one, but we'd like to create a new object using it.
7
+
Bayangkan, kita memiliki objek yang berubah-ubah, dibuat dengan menggunakan fungsi konstruktor -- kita tidak tahu yang mana, tapi kita ingin membuat sebuah objek menggunakannya.
8
8
9
-
Can we do it like that?
9
+
Bisakah kita melakukannya?
10
10
11
11
```js
12
12
let obj2 =newobj.constructor();
13
13
```
14
14
15
-
Give an example of a constructor function for`obj`which lets such code work right. And an example that makes it work wrong.
15
+
Beri sebuah contoh dari menggunakan fungsi konstruktor untuk`obj`yang mana membiarkan kode seperti itu bekerja. Dan sebuah contoh yang mana membuat kodenya menjadi tidak bekerja semestinya.
0 commit comments