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/05-data-types/10-destructuring-assignment/article.md
-38Lines changed: 0 additions & 38 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,23 +2,14 @@
2
2
3
3
دو ساختار داده پر استفاده در جاوااسکریپت `Object` و `Array` هستند.
4
4
5
-
<<<<<<< HEAD
6
5
- شیءها به ما این امکان را میدهند تا چیزی بسازیم که المانهای داده را به واسطه کلید ذخیره کند.
7
6
- آرایهها به ما امکان جمعآوری المانهای داده را در لیستی مرتب میدهند.
8
-
=======
9
-
- Objects allow us to create a single entity that stores data items by key.
10
-
- Arrays allow us to gather data items into an ordered list.
11
-
>>>>>>> 7000ede297bfd688f9a3767e8ca43abd9242f322
12
7
13
8
اگرچه، زمانی که ما آنها را به تابع میدهیم، ممکن است که نیازی به کل یک شیء/آرایه نباشد. شاید تنها قطعههای تکی نیاز باشد.
14
9
15
10
*مقداردهیِ تجزیهکنندهی ساختار (Destructuring assignment)* یک سینتکس خاص است که به ما امکان میدهد تا آرایهها یا شیءها را درون چند متغیر «پخش کنیم» چون بعضی اوقات این موضوع کار را راحتتر میکند.
16
11
17
-
<<<<<<< HEAD
18
12
تخریب ساختار همچنین با تابعهای پیچیده که تعداد زیادی پارامتر، مقدارهای پیشفرض و... دارند هم به خوبی کار میکند. به زودی آن را خواهیم دید.
19
-
=======
20
-
*Destructuring assignment* is a special syntax that allows us to "unpack" arrays or objects into a bunch of variables, as sometimes that's more convenient.
21
-
>>>>>>> 7000ede297bfd688f9a3767e8ca43abd9242f322
22
13
23
14
## تجزیه ساختار آرایه
24
15
@@ -85,21 +76,12 @@ alert( title ); // Consul
85
76
let [a, b, c] = "abc"; // ["a", "b", "c"]
86
77
let [one, two, three] = new Set([1, 2, 3]);
87
78
```
88
-
<<<<<<< HEAD
89
79
این کار میکند چون از درون، یک مقداردهی تجزیهکنندهی ساختار با حلقه زدن در مقدار سمت راست کار میکند. برای فراخوانی `for..of` در مقدار سمت راست `=` و تخصیص دادن مقدارها، به نوعی خوش سینتکس است.
90
80
````
91
81
92
82
93
83
````smart header="در سمت چپ به هر چیزی تخصیص دهید"
94
84
ما میتوانیم از «قابل مقداردهیها» در سمت چپ استفاده کنیم.
95
-
=======
96
-
That works, because internally a destructuring assignment works by iterating over the right value. It's a kind of syntax sugar for calling `for..of` over the value to the right of `=` and assigning the values.
97
-
````
98
-
99
-
100
-
````smart header="Assign to anything at the left-side"
101
-
We can use any "assignables" on the left side.
102
-
>>>>>>> 7000ede297bfd688f9a3767e8ca43abd9242f322
103
85
104
86
برای مثال، یک ویژگی شیء:
105
87
```js run
@@ -196,13 +178,7 @@ alert(rest.length); // 2
196
178
197
179
مقدار `rest` آرایهای از المانهای باقی مانده است.
198
180
199
-
<<<<<<< HEAD
200
181
میتوانیم از هر اسم دیگری به جای `rest` برای متغیر استفاده کنیم، فقط مطمئن شوید که قبل از آن سه نقطه وجود دارد و در انتهای مقداردهی تجزیهکنندهی ساختار قرار میگیرد.
201
-
=======
202
-
The value of `rest` is the array of the remaining array elements.
203
-
204
-
We can use any other variable name in place of `rest`, just make sure it has three dots before it and goes last in the destructuring assignment.
205
-
>>>>>>> 7000ede297bfd688f9a3767e8ca43abd9242f322
206
182
207
183
```js run
208
184
let [name1, name2, *!*...titles*/!*] = ["Julius", "Caesar", "Consul", "of the Roman Republic"];
@@ -258,11 +234,7 @@ alert(surname); // دریافت کند prompt هر چیزی که
258
234
let {var1, var2} = {var1:…, var2:…}
259
235
```
260
236
261
-
<<<<<<< HEAD
262
237
ما باید یک شیء موجود که میخواهیم آن را در چند متغیر پخش کنیم در سمت راست داشته باشیم. سمت چپ شامل یک «الگوی» شیء مانند برای ویژگیهای متناظر میشود. در سادهترین حالت، یک لیست از اسمهای متغیر در `{...}` است.
263
-
=======
264
-
We should have an existing object on the right side, that we want to split into variables. The left side contains an object-like "pattern" for corresponding properties. In the simplest case, that's a list of variable names in `{...}`.
265
-
>>>>>>> 7000ede297bfd688f9a3767e8ca43abd9242f322
266
238
267
239
برای مثال:
268
240
@@ -284,13 +256,7 @@ alert(height); // 200
284
256
285
257
ویژگیهای `options.title`، `options.width` و `options.height` به متغیرهای متناظر تخصیص داده شدهاند.
286
258
287
-
<<<<<<< HEAD
288
259
ترتیب مهم نیست. اینگونه هم کار میکند:
289
-
=======
290
-
Properties `options.title`, `options.width` and `options.height` are assigned to the corresponding variables.
291
-
292
-
The order does not matter. This works too:
293
-
>>>>>>> 7000ede297bfd688f9a3767e8ca43abd9242f322
294
260
295
261
```js
296
262
// تغییر دادیم let {...} ترتیب را در
@@ -454,11 +420,7 @@ alert( title ); // Menu
454
420
455
421
اگر یک شیء یا آرایه، شیء و آرایههای تودرتو دیگری را شامل شود، ما میتوانیم از الگوری پیچیدهتری در سمت چپ برای استخراج قسمتهای عمیقتر استفاده کنیم.
456
422
457
-
<<<<<<< HEAD
458
423
در کد زیر `options` یک شیء دیگری درون ویژگی `size` و یک آرایه درون ویژگی `items` دارد. الگوی سمت چپ مقداردهی ساختار یکسانی برای استخراج مقدار از آنها را دارد:
459
-
=======
460
-
In the code below `options` has another object in the property `size` and an array in the property `items`. The pattern on the left side of the assignment has the same structure to extract values from them:
: یک تاریخ با مؤلفههای داده شده در منطقهزمانی محلی میسازد. فقط دو آرگومان اول ضروری هستند.
59
59
60
-
<<<<<<< HEAD
61
-
- پارامتر `year` باید حتما 4 رقم باشد: `2013` خوب است ولی `98` نه.
60
+
- پارامتر `year` باید 4 رقم باشد: برای سازگاری، 2 رقم هم مورد قبول است و به صورت `19xx` فرض میشود، برای مثال `98` با `1998` یکسان است اما همیشه استفاده از 4 رقم پیشنهاد میشود.
62
61
- شمارش پارامتر `month` از `0` (ژانویه) تا `11` (دسامبر) است.
63
62
- پارامتر `date` در واقع روز ماه است، اگر وارد نشود `1` فرض میشود.
64
63
- اگر `hours/minutes/seconds/ms` وارد نشوند،برای آنها `0` در نظر گرفته میشود.
65
-
=======
66
-
- The `year` should have 4 digits. For compatibility, 2 digits are also accepted and considered `19xx`, e.g. `98` is the same as `1998` here, but always using 4 digits is strongly encouraged.
67
-
- The `month` count starts with `0` (Jan), up to `11` (Dec).
68
-
- The `date` parameter is actually the day of month, if absent then `1` is assumed.
69
-
- If `hours/minutes/seconds/ms` is absent, they are assumed to be equal `0`.
[JSON](http://fa.wikipedia.org/wiki/جی%E2%80%8Cسان) (نشانهگذاری شیء جاوااسکریپت، جِیسان) یک فرمت کلی برای نمایش مقدارها و شیءها است. جِیسان در استاندارد [RFC 4627](http://tools.ietf.org/html/rfc4627) شرح داده شده است. در ابتدا برای جاوااسکریپت ساخته شد اما بسیاری از زبانهای دیگر هم کتابخانههایی برای بکاربردن آن دارند. پس هنگامی که سمت کاربر سایت از جاوااسکریپت و سمت سرور با زبانهای Ruby/PHP/Java/یا هر چیز دیگر نوشته شده باشد، استفاده از جیسان برای رد و بدل کردن داده آسان است.
32
-
=======
33
-
The [JSON](https://en.wikipedia.org/wiki/JSON) (JavaScript Object Notation) is a general format to represent values and objects. It is described as in [RFC 4627](https://tools.ietf.org/html/rfc4627) standard. Initially it was made for JavaScript, but many other languages have libraries to handle it as well. So it's easy to use JSON for data exchange when the client uses JavaScript and the server is written on Ruby/PHP/Java/Whatever.
Copy file name to clipboardExpand all lines: 1-js/06-advanced-functions/01-recursion/article.md
+1-5Lines changed: 1 addition & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -535,11 +535,7 @@ list.next = list.next.next;
535
535
list = { value, next -> list }
536
536
```
537
537
538
-
<<<<<<<HEAD
539
-
درختها مانند المانهای HTML یا درخت بخش اداری در این فصل هم به طور طبیعی بازگشتی هستند: آنها شاخهشاخه میشوند و هر شاخه میتواند شاخههای دیگر هم داشته باشد.
540
-
=======
541
-
Trees like HTML elements tree or the department tree from this chapter are also naturally recursive: they have branches and every branch can have other branches.
542
-
>>>>>>>7000ede297bfd688f9a3767e8ca43abd9242f322
538
+
درختها مانند المانهای HTML یا درخت بخش اداری در این فصل هم به طور طبیعی بازگشتی هستند: آنها شاخههایی دارند و هر شاخه میتواند شاخههای دیگر هم داشته باشد.
543
539
544
540
همانطور که در مثال `sumSalary` دیدیم تابعهای بازگشتی میتوانند برای پیمایش درون آنها استفاده شوند.
Copy file name to clipboardExpand all lines: 1-js/06-advanced-functions/05-global-object/article.md
+1-5Lines changed: 1 addition & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -25,11 +25,7 @@ var gVar = 5;
25
25
alert(window.gVar); // 5 (به یک ویژگی از شیء گلوبال تبدیل شد)
26
26
```
27
27
28
-
<<<<<<< HEAD
29
-
اعلان تابع (عبارات دارای کلمه کلیدی `تابع` در جریان کد اصلی، نه عبارات تابع) نیز همین تأثیر را دارد.
30
-
=======
31
-
Function declarations have the same effect (statements with `function` keyword in the main code flow, not function expressions).
32
-
>>>>>>> 7000ede297bfd688f9a3767e8ca43abd9242f322
28
+
Function declarationها (عبارات دارای کلمه کلیدی `function` در جریان کد اصلی، نه Function expressionها) نیز همین تأثیر را دارد.
33
29
34
30
لطفا به آن تکیه نکنید! این رفتار به دلایل سازگاری وجود دارد. اسکریپتهای مدرن از [ماژولهای جاوااسکریپت](info:modules) در مواردی که چنین چیزی اتفاق نمیافتد استفاده میکنند.
حالا کار میکند چون اسم `"func"` یک تابع محلی است. این اسم از بیرون دریافت نمیشود (و آنجا هم قابل رویت نیست). مشخصات زبان تضمین میکند که این اسم همیشه به تابع کنونی رجوع میکند.
327
327
328
-
<<<<<<< HEAD
329
-
کد بیرونی هنوز هم متغیر `sayHi` یا `welcome` خود را دارد. و `func` یک «اسم تابع درونی» است، جوری که تابع میتوانند از درون خودش را فراخوانی کند.
330
-
=======
331
-
The outer code still has its variable `sayHi` or `welcome`. And `func` is an "internal function name", the way for the function to can call itself reliably.
332
-
>>>>>>> 7000ede297bfd688f9a3767e8ca43abd9242f322
328
+
کد بیرونی هنوز هم متغیر `sayHi` یا `welcome` خود را دارد. و `func` یک «اسم درونی تابع» است، جوری که تابع میتوانند از درون خودش را فراخوانی کند.
333
329
334
330
```smart header="چنین چیزی برای Function Declaration وجود ندارد"
335
331
خصوصیت «اسم درونی» که اینجا توضیح داده شد فقط برای Function Expessionها قابل استفاده است نه برای Function Declarationها. برای Function Declarationها، سینتکسی برای اضاف کردن اسم «درونی» وجود ندارد.
برای `setInterval` تابع تا زمانی که `clearInterval` فراخوانی شود درون حافظه میماند.
234
234
235
-
<<<<<<< HEAD
236
235
یک عارضه جانبی وجود دارد. یک تابع به محیط لغوی بیرونی رجوع میکند پس، تا زمانی که تابع وجود داشته باشد، متغیرهای بیرونی هم وجود خواهند داشت. آنها حافظه بسیار بیشتری را نسبت به خود تابع اشغال میکنند. پس زمانی که دیگر نیازی به تابع زمانبندی شده نداریم، بهتر است که آن را لغو کنیم حتی اگر خیلی کوچک باشد.
237
-
=======
238
-
There's a side effect. A function references the outer lexical environment, so, while it lives, outer variables live too. They may take much more memory than the function itself. So when we don't need the scheduled function anymore, it's better to cancel it, even if it's very small.
239
-
>>>>>>> 7000ede297bfd688f9a3767e8ca43abd9242f322
240
236
````
241
237
242
238
## تابع setTimeout بدون تاخیر
@@ -298,16 +294,9 @@ setTimeout(function run() {
298
294
299
295
لطفا در نظر داشته باشید که روشهای زمانبندی فاصله زمانی دقیق را *تضمین* نمیکنند.
300
296
301
-
<<<<<<< HEAD
302
297
برای مثال، تایمر درون مرورگر ممکن است به دلایل زیادی کند شود:
303
298
- کارهای زیادی به پردازنده سپرده شده است.
304
299
- تب (tab) مرورگر در حالت پسزمینه است.
305
-
- لپ تاپ در حال استفاده از باتری است.
306
-
=======
307
-
For example, the in-browser timer may slow down for a lot of reasons:
308
-
- The CPU is overloaded.
309
-
- The browser tab is in the background mode.
310
-
- The laptop is on battery saving mode.
311
-
>>>>>>> 7000ede297bfd688f9a3767e8ca43abd9242f322
300
+
- لپ تاپ در حالت صرفهجویی باتری است.
312
301
313
302
All that may increase the minimal timer resolution (the minimal delay) to 300ms or even 1000ms depending on the browser and OS-level performance settings.
Copy file name to clipboardExpand all lines: 1-js/06-advanced-functions/09-call-apply-decorators/04-throttle/task.md
-6Lines changed: 0 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,15 +8,9 @@ importance: 5
8
8
9
9
زمانی که چند بار فراخوانی شد، فقط یک بار به ازای هر `ms` میلیثانیه `f` را فرا میخواند.
10
10
11
-
<<<<<<< HEAD
12
11
تفاوت این تابع با معلقکننده این است که کاملا یک دکوراتور متفاوت است:
13
12
-`debounce` تابع را بعد از مدت «آرامشدن» اجرا میکند. برای پردازش نتیجه نهایی خوب است.
14
13
-`throttle` هر بار بعد از گذشت `ms` میلیثانیه تابع را اجرا میکند. برای بروزرسانیهای منظم که نباید زیاد انجام شوند خوب است.
15
-
=======
16
-
Compared to the debounce decorator, the behavior is completely different:
17
-
-`debounce` runs the function once after the "cooldown" period. Good for processing the final result.
18
-
-`throttle` runs it not more often than given `ms` time. Good for regular updates that shouldn't be very often.
19
-
>>>>>>> 7000ede297bfd688f9a3767e8ca43abd9242f322
20
14
21
15
به عبارتی دیگر، `throttle` مانند یک منشی است که تماسهای تلفنی را میپذیرد اما پس از `ms` میلیثانیه فقط یک بار مزاحم رئیس میشود (تابع واقعی `f` را فراخوانی میکند).
0 commit comments