Skip to content

Commit fb61ba9

Browse files
authored
Update solution.md
1 parent 28c8e97 commit fb61ba9

1 file changed

Lines changed: 9 additions & 12 deletions

File tree

  • 1-js/99-js-misc/04-reference-type/2-check-syntax
Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,29 @@
1-
**خطا**!
1+
**Error**!
22

3-
کد زیر را مدنظر داشته باشید:
3+
Try it:
44

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

11-
(user.go)() // خطا دارد!
11+
(user.go)() // error!
1212
```
1313

14-
پیام خطا در بیشتر مرورگر ها اطلاعاتی بابت اینکه چه اشتباهی رخ داده است نمیدهد.
14+
The error message in most browsers does not give us much of a clue about what went wrong.
1515

16+
**The error appears because a semicolon is missing after `user = {...}`.**
1617

17-
** این خطا نشان داده میشود چون سمیکالن بعد از این دستور فراموش شده است `{...} = user`.**
18-
19-
20-
جاوااسکریپت به صورت پیش فرض سمیکالن را در براکت قبل از دستور `()(user.go)` اضافه نمیکند. سپس کد به این صورت خوانده میشود:
18+
JavaScript does not auto-insert a semicolon before a bracket `(user.go)()`, so it reads the code like:
2119

2220
```js no-beautify
2321
let user = { go:... }(user.go)()
2422
```
2523

26-
بنابراین جاوااسکریپت حدس میزند که ما درواقع آبجکت `{ ... :go }` را به عنوان یک تابع با آرگومان های `(user.go)` صدا زده ایم. و سپس چون به `let user` میرسیم آبجکت `user` به صورت تعریف نشده معرفی میشود و ما ارور را مشاهده میکنیم.
27-
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.
2825

29-
در کد زیر همه چیز خوب بنظر میرسد اگر سمیکالن را انتهای آبجکت اضافه کنیم:
26+
If we insert the semicolon, all is fine:
3027

3128
```js run
3229
let user = {
@@ -37,4 +34,4 @@ let user = {
3734
(user.go)() // John
3835
```
3936

40-
توجه داشته باشید که پرانتز اطراف `(user.go)` کاری انجام نمیدهد. معمولا در اکثر موقعیت ها اولویت پرانتز عملگر هارا تغییر میدهد, اما در اینجا فقط عملگر نقطه `.` کار میکند. سپس مورد خاصی نیست و فعلا بحث سمیکالن مهم است.
37+
Please note that parentheses 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.

0 commit comments

Comments
 (0)