Skip to content

Commit 6c37606

Browse files
authored
translated
1 parent c2246d4 commit 6c37606

File tree

1 file changed

+11
-11
lines changed
  • 1-js/04-object-basics/04-object-methods/4-object-property-this

1 file changed

+11
-11
lines changed

1-js/04-object-basics/04-object-methods/4-object-property-this/solution.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
**Answer: an error.**
1+
**Odpowiedź: błąd.**
22

3-
Try it:
3+
Uruchom ten kod:
44
```js run
55
function makeUser() {
66
return {
@@ -14,26 +14,26 @@ let user = makeUser();
1414
alert( user.ref.name ); // Error: Cannot read property 'name' of undefined
1515
```
1616

17-
That's because rules that set `this` do not look at object definition. Only the moment of call matters.
17+
Jest to spowodowane tym, że reguły ustalające wartość `this` nie uwzględniają definicji obiektu. Znaczenie ma tylko moment wywołania.
1818

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+
Wartość `this` wewnątrz `makeUser()` jest `undefined`, ponieważ jest wywołana jako funkcja, a nie jako metoda wywołania za pomocą składni z "kropką"
2020

21-
The value of `this` is one for the whole function, code blocks and object literals do not affect it.
21+
Wartość `this` jest tu ustalonawyłącznie dla tej funkcji. Bloki kodu i obiekty nie są w tym przypadku brane pod uwagę.
2222

23-
So `ref: this` actually takes current `this` of the function.
23+
Zatem `ref:this` jest równoznaczne z `this` funkcji.
2424

25-
We can rewrite the function and return the same `this` with `undefined` value:
25+
Możemy napisać tę funkcję od nowa w taki sposób, że będzie zwracała takie samo `this` z wartością `undefined`:
2626

2727
```js run
2828
function makeUser(){
29-
return this; // this time there's no object literal
29+
return this; // tym razem nie jest zwracany obiekt
3030
}
3131

3232
alert( makeUser().name ); // Error: Cannot read property 'name' of undefined
3333
```
34-
As you can see the result of `alert( makeUser().name )` is the same as the result of `alert( user.ref.name )` from the previous example.
34+
Jak widzisz wynik `alert( makeUser().name )` jest taki sam jak wynik `alert( user.ref.name )` z poprzedniego przykładu.
3535

36-
Here's the opposite case:
36+
A tutaj odwrotna sytuacja:
3737

3838
```js run
3939
function makeUser() {
@@ -52,4 +52,4 @@ let user = makeUser();
5252
alert( user.ref().name ); // John
5353
```
5454

55-
Now it works, because `user.ref()` is a method. And the value of `this` is set to the object before dot `.`.
55+
Teraz kod działa prawidłowo, ponieważ `user.ref()` jest metodą, a wartością `this` jest obiekt przed kropką `.`.

0 commit comments

Comments
 (0)