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
Copy file name to clipboardExpand all lines: 1-js/04-object-basics/04-object-methods/4-object-property-this/solution.md
+9-9Lines changed: 9 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
-
**Answer: an error.**
1
+
**Răspuns: o eroare.**
2
2
3
-
Try it:
3
+
Încercați:
4
4
```js run
5
5
functionmakeUser() {
6
6
return {
@@ -11,18 +11,18 @@ function makeUser() {
11
11
12
12
let user =makeUser();
13
13
14
-
alert( user.ref.name ); //Error: Cannot read property 'name' of undefined
14
+
alert( user.ref.name ); //Eroare: Cannot read property 'name' of undefined
15
15
```
16
16
17
-
That's because rules that set `this`do not look at object definition. Only the moment of call matters.
17
+
Acest lucru se datorează faptului că regulile care setează `this`nu se uita la definirea obiectului. Doar momentul apelului contează .
18
18
19
-
Here the value of `this`inside `makeUser()`is`undefined`, because it is called as a function, not as a method with "dot" syntax.
19
+
Aici valoarea variabilei `this`din interiorul funcției `makeUser()`este`undefined`, deoarece este apelată ca funcție, nu ca o metodă cu sintaxa "punct".
20
20
21
-
The value of `this`is one for the whole function, code blocks and object literals do not affect it.
21
+
Valoarea variabilei `this`este unică pentru întreaga funcția, blocurile de cod și obiectele literale nu o afectează.
22
22
23
-
So `ref: this`actually takes current `this`of the function.
23
+
În concluzie `ref: this`preia de fapt variabila curentă `this`a funcției.
24
24
25
-
Here's the opposite case:
25
+
Iată cazul opus:
26
26
27
27
```js run
28
28
functionmakeUser() {
@@ -41,4 +41,4 @@ let user = makeUser();
41
41
alert( user.ref().name ); // John
42
42
```
43
43
44
-
Now it works, because `user.ref()`is a method. And the value of `this`is set to the object before dot`.`.
44
+
Acum funcționează, pentru că `user.ref()`este o metodă. Iar valoarea variabilei `this`este setată la obiectul dinaintea punctului`.`.
0 commit comments