Skip to content

Commit c9694bb

Browse files
committed
merging all conflicts
2 parents 4309102 + bae0ef4 commit c9694bb

16 files changed

Lines changed: 97 additions & 6 deletions

File tree

1-js/02-first-steps/05-types/article.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,23 @@ n = 12.345;
4646
alert( "not a number" / 2 ); // NaN، چنین تقسیمی اشتباه است
4747
```
4848

49+
<<<<<<< HEAD
4950
هر عملی بر روی `NaN` نتیجه `NaN` خواهد داشت:
51+
=======
52+
`NaN` is sticky. Any further mathematical operation on `NaN` returns `NaN`:
53+
>>>>>>> bae0ef44d0208506f6e9b7f3421ee640ab41af2b
5054

5155
```js run
52-
alert( "not a number" / 2 + 5 ); // NaN
56+
alert( NaN + 1 ); // NaN
57+
alert( 3 * NaN ); // NaN
58+
alert( "not a number" / 2 - 1 ); // NaN
5359
```
5460

61+
<<<<<<< HEAD
5562
در نتیجه اگر `NaN` در عملیات ریاضیاتی‌ای وجود داشته باشد، بر روی تمام معادله تاثیر می‌گذارد (نتیجه معادله برابر `NaN` خواهد بود).
63+
=======
64+
So, if there's a `NaN` somewhere in a mathematical expression, it propagates to the whole result (there's only one exception to that: `NaN ** 0` is `1`).
65+
>>>>>>> bae0ef44d0208506f6e9b7f3421ee640ab41af2b
5666

5767
```smart header="عملیات ریاضیاتی امن هستند"
5868
عملیات ریاضی در جاوااسکریپت امن است. ما هر نوع عملی می‌توانیم انجام دهیم مانند تقسیم بر صفر، رفتار کردن با رشته‌های غیر عددی همانند اعداد و غیره.

1-js/02-first-steps/12-nullish-coalescing-operator/article.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,11 @@ alert(height ?? 100); // 0
106106
107107
## اولویت
108108
109+
<<<<<<< HEAD
109110
اولویت عملگر `??` تقریبا برابر با عملگر `||` است، اما کمتر. اولویت آن در [جدول MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Operator_Precedence#Table) برابر با `5` است، در حالی که اولویت `||` برابر با `6` است.
111+
=======
112+
The precedence of the `??` operator is the same as `||`. They both equal `4` in the [MDN table](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Operator_Precedence#Table).
113+
>>>>>>> bae0ef44d0208506f6e9b7f3421ee640ab41af2b
110114
111115
این یعنی که درست مانند `||`، عملگر nullish coalescing `??` قبل از `=` و `?` ارزیابی می‌شود، اما بعد از بیشتر عملیات‌ها مانند `+`، `-` ارزیابی می‌شود.
112116

1-js/02-first-steps/16-function-expressions/article.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@ function sayHi() {
1212

1313
یک سینتکس دیگر هم برای ساخت تابع وجود دارد که *Function Expression* نامیده می‌شود.
1414

15+
<<<<<<< HEAD
1516
این سینتکس به ما این امکان را می‌دهد که بین هر عبارتی یک تابع جدید بسازیم.
17+
=======
18+
It allows us to create a new function in the middle of any expression.
19+
>>>>>>> bae0ef44d0208506f6e9b7f3421ee640ab41af2b
1620
1721
برای مثال:
1822

1-js/02-first-steps/17-arrow-functions-basics/article.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,11 @@ let sum = function(a, b) {
3333
alert(sum(1, 2)); // 3
3434
```
3535

36+
<<<<<<< HEAD
3637
همانطور که می‌بینید `(a, b) => a + b` بدین معنی‌ست که این تابع دو آرگومان با نام‌های `a` و `b` می‌پذیرد. و هنگام اجرا شدن، مقدار `a + b` را حساب می‌کند و نتیجه را برمی‌گرداند.
38+
=======
39+
As you can see, `(a, b) => a + b` means a function that accepts two arguments named `a` and `b`. Upon the execution, it evaluates the expression `a + b` and returns the result.
40+
>>>>>>> bae0ef44d0208506f6e9b7f3421ee640ab41af2b
3741
3842
- اگر فقط یک آرگومان داشته باشیم می‌توانیم پرانتزهای دور آرگومان را حذف کنیم و کد را از این هم کوتاه‌تر کنیم.
3943

@@ -84,7 +88,11 @@ welcome();
8488
let sum = (a, b) => { // کمانک یک تابع چندخظی را دربرمی‌گیرد
8589
let result = a + b;
8690
*!*
91+
<<<<<<< HEAD
8792
return result; // اگر از کمانک استفاده کنیم باید از return استفاده کنیم
93+
=======
94+
return result; // if we use curly braces, then we need an explicit "return"
95+
>>>>>>> bae0ef44d0208506f6e9b7f3421ee640ab41af2b
8896
*/!*
8997
};
9098

1-js/04-object-basics/04-object-methods/8-chain-calls/_js.view/solution.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,6 @@ let ladder = {
1111
},
1212
showStep: function() {
1313
alert(this.step);
14+
return this;
1415
}
1516
};

1-js/04-object-basics/04-object-methods/8-chain-calls/_js.view/test.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,14 @@ describe('Ladder', function() {
3232
it('down().up().up().up() ', function() {
3333
assert.equal(ladder.down().up().up().up().step, 2);
3434
});
35+
36+
it('showStep() should return this', function() {
37+
assert.equal(ladder.showStep(), ladder);
38+
});
39+
40+
it('up().up().down().showStep().down().showStep()', function () {
41+
assert.equal(ladder.up().up().down().showStep().down().showStep().step, 0)
42+
});
3543

3644
after(function() {
3745
ladder.step = 0;

1-js/04-object-basics/07-optional-chaining/article.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,11 @@ alert(user.address.street); // !خطا
2525

2626
ولی در بسیاری از موارد عملی، ما ترجیح می‌دهیم به جای خطا، ‍`undefined` را دریافت کنیم (به معنای "بدون خیابان").
2727

28+
<<<<<<< HEAD
2829
...و مثالی دیگر، در توسعه وب، ما می‌توانیم یک شیء که با یک المان در صفحه مطابقت دارد را با استفاده از یک متد خاص، مانند `document.querySelector('.elem')` بگیریم و این متد هنگامی که چنین المانی وجود نداشته باشد `null` را برمی‌گرداند:
30+
=======
31+
...and another example. In Web development, we can get an object that corresponds to a web page element using a special method call, such as `document.querySelector('.elem')`, and it returns `null` when there's no such element.
32+
>>>>>>> bae0ef44d0208506f6e9b7f3421ee640ab41af2b
2933
3034
```js run
3135
// document.querySelector('.elem') خواهد شد اگر المنت وجود نداشته باشد null برابر با

1-js/05-data-types/10-destructuring-assignment/article.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,13 @@
55
- شیءها به ما این امکان را می‌دهند تا چیزی بسازیم که المان‌های داده را به واسطه کلید ذخیره کند.
66
- آرایه‌ها به ما امکان جمع‌آوری المان‌های داده را در لیستی مرتب می‌دهند.
77

8+
<<<<<<< HEAD
89
اگرچه، زمانی که ما آنها را به تابع می‌دهیم، ممکن است که نیازی به کل یک شیء/آرایه نباشد. ممکن است تنها قطعه‌های تکی نیاز باشد.
910

1011
*مقداردهیِ تجزیه‌کننده‌ی ساختار (Destructuring assignment)* یک سینتکس خاص است که به ما امکان می‌دهد تا آرایه‌ها یا شیءها را درون چند متغیر «پخش کنیم» چون بعضی اوقات این موضوع کار را راحت‌تر می‌کند.
12+
=======
13+
Although, when we pass those to a function, it may need not be an object/array as a whole. It may need individual pieces.
14+
>>>>>>> bae0ef44d0208506f6e9b7f3421ee640ab41af2b
1115
1216
تخریب ساختار همچنین با تابع‌های پیچیده که تعداد زیادی پارامتر، مقدارهای پیش‌فرض و... دارند هم به خوبی کار می‌کند. به زودی آن را خواهیم دید.
1317

1-js/11-async/01-callbacks/article.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,14 @@ loadScript("/my/script.js", function(error, script) {
164164

165165
## هرم عذاب
166166

167+
<<<<<<< HEAD
167168
در نگاه اول این روش برای نوشتن کدهای ناهمگام پایدار بنظر میرسد. که واقعا هم این چنین است ولی برای نهایتا یک یا دو فراخوان تودرتو!!
168169
اما برای چندین عمل ناهمگام که یکی پس از دیگری اتفاق میفتد چیزی شبیه به این خواهیم داشت:
170+
=======
171+
At first glance, it looks like a viable approach to asynchronous coding. And indeed it is. For one or maybe two nested calls it looks fine.
172+
173+
But for multiple asynchronous actions that follow one after another, we'll have code like this:
174+
>>>>>>> bae0ef44d0208506f6e9b7f3421ee640ab41af2b
169175
170176
```js
171177
loadScript("1.js", function(error, script) {
@@ -197,7 +203,16 @@ loadScript("1.js", function(error, script) {
197203
2. `2.js`را بارگذاری میکنیم سپس اگر خطایی نداشت
198204
3. `3.js` را بارگذاری میکنیم سپس اگر خطایی نداشت -- کار دیگری انجام میدهیم`(*)`
199205

206+
<<<<<<< HEAD
200207
هرچقدر فراخوانی های ما تودرتو باشند کدهای مارا عمیقتر و غیرقابل فهم و مدیریت میکنند مخصوصا اگر به جای ... ها کدهای واقعی داشته باشیم که خود شامل حلقه ها و شرط ها و هر جمله دیگری هستند.
208+
=======
209+
In the code above:
210+
1. We load `1.js`, then if there's no error...
211+
2. We load `2.js`, then if there's no error...
212+
3. We load `3.js`, then if there's no error -- do something else `(*)`.
213+
214+
As calls become more nested, the code becomes deeper and increasingly more difficult to manage, especially if we have real code instead of `...` that may include more loops, conditional statements and so on.
215+
>>>>>>> bae0ef44d0208506f6e9b7f3421ee640ab41af2b
201216
202217
که معمولا به آن "جهنم فراخوانی" (callback-hell / pyramid of doom) میگویند.
203218

@@ -262,7 +277,13 @@ function step3(error, script) {
262277
```
263278
همینجوری که مشاهده میکنید نتیجه تغییری نکرد ولی از تودرتو بودن فراخوانی ها با تعریف کردن توابع به صورت جداگانه برای هر مرحله از تودرتو بودن عمیق جلوگیری کردیم.
264279

280+
<<<<<<< HEAD
265281
این روش کار میکند ولی کدش تکه تکه و جدا از هم است که خواندن آن را سخت میکند. همانطور که احتمالا دیدید لازم است در حین خواندن از جایی به جای دیگر بپرید. این طور اصلا راحت نیست مخصوصا اگر به کد آشنا نباشید و ندانید باید برای ادامه کد کجا را بخوانید.
282+
=======
283+
See? It does the same thing, and there's no deep nesting now because we made every action a separate top-level function.
284+
285+
It works, but the code looks like a torn apart spreadsheet. It's difficult to read, and you probably noticed that one needs to eye-jump between pieces while reading it. That's inconvenient, especially if the reader is not familiar with the code and doesn't know where to eye-jump.
286+
>>>>>>> bae0ef44d0208506f6e9b7f3421ee640ab41af2b
266287
267288
همچنین توابعِ `step*` فقط یکبار استفاده میشوند و فقط برای جلوگیری از بوجود امدن جهنم فراخوانی و تودرتویی بیش از حد تعریف شده اند که باعث بی نظمی زیادی در کد میشوند.
268289

1-js/11-async/03-promise-chaining/article.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ new Promise(function(resolve, reject) {
120120
});
121121
```
122122

123-
Here the first `.then` shows `1` and returns `new Promise(…)` in the line `(*)`. After one second it resolves, and the result (the argument of `resolve`, here it's `result * 2`) is passed on to handler of the second `.then`. That handler is in the line `(**)`, it shows `2` and does the same thing.
123+
Here the first `.then` shows `1` and returns `new Promise(…)` in the line `(*)`. After one second it resolves, and the result (the argument of `resolve`, here it's `result * 2`) is passed on to the handler of the second `.then`. That handler is in the line `(**)`, it shows `2` and does the same thing.
124124

125125
So the output is the same as in the previous example: 1 -> 2 -> 4, but now with 1 second delay between `alert` calls.
126126

0 commit comments

Comments
 (0)