Skip to content

Commit 5acaad4

Browse files
authored
section translated
1 parent 57f1e9e commit 5acaad4

File tree

1 file changed

+9
-10
lines changed
  • 1-js/04-object-basics/04-object-methods/2-check-syntax

1 file changed

+9
-10
lines changed
Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,28 @@
1-
**Error**!
1+
**Błąd**!
22

3-
Try it:
3+
Sprawdź ten kod:
44

55
```js run
66
let user = {
77
name: "John",
88
go: function() { alert(this.name) }
99
}
1010

11-
(user.go)() // error!
11+
(user.go)() // błąd!
1212
```
13+
W większości przeglądarek wiadomość o błędzie nie zawiera zbyt wielu szczegółów mówiących co poszło nie tak.
1314

14-
The error message in most browsers does not give us much of a clue about what went wrong.
15+
**Błąd wystąpił ponieważ nie ma średnika po`user = {...}`.**
1516

16-
**The error appears because a semicolon is missing after `user = {...}`.**
17-
18-
JavaScript does not auto-insert a semicolon before a bracket `(user.go)()`, so it reads the code like:
17+
JavaScript nie wstawia automatycznie średnika przed nawiasem `(user.go)()`, więc czyta kod w ten sposób:'
1918

2019
```js no-beautify
2120
let user = { go:... }(user.go)()
2221
```
2322

24-
Then we can also see that such a joint expression is syntactically a call of the object `{ go: ... }` as a function with the argument `(user.go)`. And that also happens on the same line with `let user`, so the `user` object has not yet even been defined, hence the error.
23+
Teraz widzimy, że taka składnia jest w zasadzie wywołaniem funkcji `{ go: ... }` z argumentem `(user.go)`. W dodatku wywołanie to znajduje się w tej samej linijce co `let user`, więc do obiekt `user` nie został jeszcze nawet zdefiniowany, dlatego pojawia się błąd.
2524

26-
If we insert the semicolon, all is fine:
25+
Jeśli wstawimy średnik, kod będzie działać:
2726

2827
```js run
2928
let user = {
@@ -34,4 +33,4 @@ let user = {
3433
(user.go)() // John
3534
```
3635

37-
Please note that brackets around `(user.go)` do nothing here. Usually they setup the order of operations, but here the dot `.` works first anyway, so there's no effect. Only the semicolon thing matters.
36+
Miej na uwadze, że nawiasy wokół `(user.go)` nie mają tu żadnego znaczenia. Zazwyczaj służą do zachowania kolejności wykonywania działań, jednak w tym przypadku kropka `.` i tak ma pierwszeństwo. Jedynie średnik jest tu niezbędny.

0 commit comments

Comments
 (0)