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/01-getting-started/1-intro/article.md
+5Lines changed: 5 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -72,8 +72,13 @@
72
72
73
73
به این موضوع Same Origin Policy گفته میشود. برای آنکه بتوان در این حالت کار کرد هر دو صفحه باید یک کد جاوااسکریپت مخصوصی داشته باشند تا بتوان این تبادل اطلاعات را انجام داد.
74
74
75
+
<<<<<<< HEAD
75
76
این محدودیتها برای امنیت کاربر است. صفحهای از دامنه `http://anysite.com/` که کاربر آن را باز کرده است نباید به تب دیگر مرورگر با آدرس `http://gmail.com/` دسترسی داشته باشد و اطلاعات آن را به سرقت ببرد.
76
77
- جاوااسکریپت میتواند در سطح شبکه با سِروِرها ارتباط بر قرار کند. اما توانایی آن در دریافت اطلاعات از دیگر دامنهها و سایتها با مسائلی مواجه هست. اگر چنین چیزی امکانپذیر است اما به اجازه مستقیم از طرف سِروِرِ مربوطه نیازمند میباشد. تمام این محدودیتها برای امنیت کاربر قرار داده شدهاند.
78
+
=======
79
+
This limitation is, again, for the user's safety. A page from `http://anysite.com` which a user has opened must not be able to access another browser tab with the URL `http://gmail.com`, for example, and steal information from there.
80
+
- JavaScript can easily communicate over the net to the server where the current page came from. But its ability to receive data from other sites/domains is severely limited. Though possible, it requires explicit agreement (expressed in HTTP headers) from the remote side. Once again, that's a safety limitation.
Copy file name to clipboardExpand all lines: 1-js/02-first-steps/04-variables/article.md
+52Lines changed: 52 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -88,16 +88,26 @@ let user = 'John'
88
88
*!*var*/!* message ='سلام';
89
89
```
90
90
91
+
<<<<<<< HEAD
91
92
کلیدواژه `var` تقریبا* با*`let` یکسان است. آن هم یک متغیر را تعریف میکند، ولی روش کار آن قدیمی است.
92
93
93
94
تفاوتهای کوچکی بین این دو وجود دارد که در حال حاضر به آن نمیپردازیم. در مبحث <info:var> با جزییات به آن خواهیم پرداخت.
95
+
=======
96
+
The `var` keyword is *almost* the same as `let`. It also declares a variable but in a slightly different, "old-school" way.
97
+
98
+
There are subtle differences between `let` and `var`, but they do not matter to us yet. We'll cover them in detail in the chapter <info:var>.
99
+
>>>>>>> 52c1e61915bc8970a950a3f59bd845827e49b4bf
94
100
````
95
101
96
102
## یک مقایسهی واقعی
97
103
98
104
برای درک مفهوم متغیر، میتوانیم آن را یک جعبه برای نگهداری اطلاعات تصور کنیم، که یک نام منحصربهفرد روی آن چسباندهایم.
99
105
106
+
<<<<<<< HEAD
100
107
برای نمونه، تصور کنید متغیر "`message`" در جعبهای با برچسب `message` و با مقدار "`سلام!`" داخل آن وجود دارد:
108
+
=======
109
+
For instance, the variable `message` can be imagined as a box labelled `"message"` with the value `"Hello!"` in it:
110
+
>>>>>>> 52c1e61915bc8970a950a3f59bd845827e49b4bf
101
111
102
112

103
113
@@ -171,7 +181,11 @@ let userName;
171
181
let test123;
172
182
```
173
183
184
+
<<<<<<< HEAD
174
185
زمانی که یک نام متشکل از چند کلمه است، عموما از روش [camelCase](https://fa.wikipedia.org/wiki/نگارش_شتری) استفاده میشود. به این صورت که کلمات یکی پس از دیگری پشت هم نوشته میشوند و حرف اول هر کلمه (به جز حرف اول کلمه اول) به حرف بزرگ است: `myVeryLongName`.
186
+
=======
187
+
When the name contains multiple words, [camelCase](https://en.wikipedia.org/wiki/CamelCase) is commonly used. That is: words go one after another, with each word except the first starting with a capital letter: `myVeryLongName`.
188
+
>>>>>>> 52c1e61915bc8970a950a3f59bd845827e49b4bf
175
189
176
190
همینطور از `'$'` و `'_'` نیز میتوان استفاده کرد. آنها فقط علامت هستند و معنی خاصی ندارند و همانند حروف قابل استفاده هستند.
177
191
@@ -196,15 +210,24 @@ let my-name; // خطهای پیوند '-' در نامها ممنوع هس
196
210
متغیرهای apple و Apple دو متغیر متفاوت هستند.
197
211
```
198
212
213
+
<<<<<<< HEAD
199
214
````smart header="کاراکترهای غیر انگلیسی مجاز هستند ولی توصیه نمیشوند"
200
215
امکان استفاده از هر زبانی، شامل حروف cyrillic، لوگوگرامهای چینی و دیگر زبانها وجود دارد، مثلا اینگونه::
216
+
=======
217
+
````smart header="Non-Latin letters are allowed, but not recommended"
218
+
It is possible to use any language, including Cyrillic letters, Chinese logograms and so on, like this:
219
+
>>>>>>> 52c1e61915bc8970a950a3f59bd845827e49b4bf
201
220
202
221
```js
203
222
let имя = '...';
204
223
let 我 = '...';
205
224
```
206
225
226
+
<<<<<<< HEAD
207
227
از نظر فنی، اینها درست کار میکنند و مجاز هستند، ولی بر اساس یک قائده بینالمللی برای نام متغیرها از زبان انگلیسی استفاده میشود. حتی اگر اسکریپتی کوچک مینویسیم، ممکن است تا مدت طولانیای مورد استفاده و توسعه قرار بگیرد. اشخاصی از سایر کشورها ممکن است نیاز باشد روزی آن اسکریپت را بخوانند.
228
+
=======
229
+
Technically, there is no error here. Such names are allowed, but there is an international convention to use English in variable names. Even if we're writing a small script, it may have a long life ahead. People from other countries may need to read it sometime.
myBirthday = '01.01.2001'; // !ارور، نمیتوان ثابت را دوباره مقداردهی کرد
262
285
```
263
286
287
+
<<<<<<< HEAD
264
288
وقتی برنامهنویس اطمینان دارد که متغیری هیچگاه تغییر نمیکند میتواند آن را به عنوان const تعریف کند تا برای دیگران نیز این موضوع واضح باشد.
289
+
=======
290
+
When a programmer is sure that a variable will never change, they can declare it with `const` to guarantee and communicate that fact to everyone.
291
+
>>>>>>> 52c1e61915bc8970a950a3f59bd845827e49b4bf
265
292
266
293
294
+
<<<<<<< HEAD
267
295
### ثابتهای با حروف بزرگ
296
+
=======
297
+
There is a widespread practice to use constants as aliases for difficult-to-remember values that are known before execution.
298
+
>>>>>>> 52c1e61915bc8970a950a3f59bd845827e49b4bf
268
299
269
300
به صورت یک عُرفِ همهگیر، از ثابتهای با حروف بزرگ به عنوان نام مستعار برای مقادیری که به خاطر سپردن آنها دشوار است، استفاده میشود. این دسته از ثابتها اصطلاحا prior to execution (پیش از اجرای برنامه) مقدارشان مشخص است.
270
301
@@ -291,15 +322,23 @@ alert(color); // #FF7F00
291
322
292
323
چه زمانی باید از حروف بزرگ و چه زمانی باید از حروف معمولی برای نامگذاری یک constant استفاده کنیم؟ بیایید قضیه را روشن کنیم.
293
324
325
+
<<<<<<< HEAD
294
326
ثابت بودن یک متغیر صرفا بدین معناست که مقدار آن تغییر نخواهد کرد. یک دسته از ثابتها پیش از اجرای برنامه مقدارشان مشخص خواهد بود (مثل هگزادسیمال برای رنگ قرمز) و دسته دیگر در حین اجرای (Run Time) برنامه مقدارشان مشخص میشود، اما پس از مقدار دهی اولیه مقدارشان تغییر نمیکند.
327
+
=======
328
+
Being a "constant" just means that a variable's value never changes. But some constants are known before execution (like a hexadecimal value for red) and some constants are *calculated* in run-time, during the execution, but do not change after their initial assignment.
329
+
>>>>>>> 52c1e61915bc8970a950a3f59bd845827e49b4bf
295
330
296
331
برای نمونه:
297
332
298
333
```js
299
334
const pageLoadTime = /* زمان بارگیری برای یک صفحه وب */;
300
335
```
301
336
337
+
<<<<<<< HEAD
302
338
مقدار `pageLoadTime` پیش از اجرای برنامه مشخص نبوده و به همین دلیل به صورت عادی نوشته شده است. اما همچنان یک ثابت است چراکه زمان اجرای برنامه بعد از مقداردهی دیگر تغییر نخواهد کرد.
339
+
=======
340
+
The value of `pageLoadTime` is not known before the page load, so it's named normally. But it's still a constant because it doesn't change after the assignment.
341
+
>>>>>>> 52c1e61915bc8970a950a3f59bd845827e49b4bf
303
342
304
343
به تعبیری دیگر، ثابتهای با حروف بزرگ فقط به عنوان نام مستعار برای مقدارهای «hard-coded» استفاده میشوند.
305
344
@@ -309,18 +348,31 @@ const pageLoadTime = /* زمان بارگیری برای یک صفحه وب */;
309
348
310
349
نام یک متغیر باید معنی واضح و روشنی داشته باشد که داده درون خود را توصیف میکند.
311
350
351
+
<<<<<<< HEAD
312
352
انتخاب نام برای متغیرها یکی از کارهای مهم و پیچیده در برنامهنویسی است. یک نگاه سریع به نام متغیرها میتواند تفاوت یک برنامهنویس تازهکار و با تجربه را نشان دهد.
313
353
314
354
در پروژههای واقعی، بجای از صفر نوشتن برنامهها، بیشتر زمان صرف اصلاح و توسعه کدهای موجود میشود. وقتی پس از مدتی به کدهای قبلی باز میگردیم، بدست آوردن اطلاعات از آن دسته کدهایی که نامگذاریهای خوبی دارند بسیار راحتتر است (منظور متغیرهایی است که نامهای خوبی دارند).
355
+
=======
356
+
Variable naming is one of the most important and complex skills in programming. A glance at variable names can reveal which code was written by a beginner versus an experienced developer.
357
+
358
+
In a real project, most of the time is spent modifying and extending an existing code base rather than writing something completely separate from scratch. When we return to some code after doing something else for a while, it's much easier to find information that is well-labelled. Or, in other words, when the variables have good names.
359
+
>>>>>>> 52c1e61915bc8970a950a3f59bd845827e49b4bf
315
360
316
361
لطفا پیش از انتخاب نام برای یک متغیر، خوب به آن فکر کنید. ثمرهی آن را خواهید دید.
317
362
318
363
بعضی از دستورالعملهای مفید:
319
364
365
+
<<<<<<< HEAD
320
366
- از نامهایی که برای انسان قابل فهم است استفاده کنید مانند `userName` یا `shoppingCart`.
321
367
- از نامهای مخفف یا کوتاه استفاده نکنید مانند `a`، `b`، `c`، مگر آنکه واقعا بدانید چه میکنید.
322
368
- نامهای کاملا واضح و مختصر انتخاب کنید. نمونههایی از نامهای بد `data` و `value` هستند. این نامها هیچچیز را توضیح نمیدهند. استفاده از این دست نامها فقط زمانی قابل قبول است که محتوای کدی که مینویسید به طور استثنا مشخص کند که data یا value به چه چیزی اشاره میکند.
323
369
- با ذهن خود و تیم کاریتان توافق نظر داشته باشید. اگر به مخاطبان وبسایتتان user میگویید، متغیرهای مرتبط را بجای `currentVisitor` یا `newManInTown` باید `currentUser` یا `newUser` بنامید.
370
+
=======
371
+
- Use human-readable names like `userName` or `shoppingCart`.
372
+
- Stay away from abbreviations or short names like `a`, `b`, and `c`, unless you know what you're doing.
373
+
- Make names maximally descriptive and concise. Examples of bad names are `data` and `value`. Such names say nothing. It's only okay to use them if the context of the code makes it exceptionally obvious which data or value the variable is referencing.
374
+
- Agree on terms within your team and in your mind. If a site visitor is called a "user" then we should name related variables `currentUser` or `newUser` instead of `currentVisitor` or `newManInTown`.
375
+
>>>>>>> 52c1e61915bc8970a950a3f59bd845827e49b4bf
324
376
325
377
```smart header="ایجاد یا استفاده مجدد?"
326
378
و آخرین نکته: برخی برنامهنویسان تنبل بجای تعریف متغیرهای جدید، از متغیرهای موجود دوباره استفاده میکنند.
0 commit comments