Skip to content

Commit 1e62f65

Browse files
committed
# Conflicts: # 1-js/01-getting-started/2-manuals-specifications/article.md # 1-js/02-first-steps/04-variables/article.md # 1-js/02-first-steps/06-type-conversions/1-primitive-conversions-questions/solution.md # 1-js/02-first-steps/06-type-conversions/article.md # 1-js/02-first-steps/07-operators/article.md # 1-js/02-first-steps/16-javascript-specials/article.md # 1-js/03-code-quality/06-polyfills/article.md # 1-js/06-advanced-functions/03-closure/article.md # 1-js/11-async/02-promise-basics/article.md # 5-network/05-fetch-crossorigin/1-do-we-need-origin/task.md
2 parents 1fc86f8 + ade541b commit 1e62f65

44 files changed

Lines changed: 332 additions & 277 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1-js/02-first-steps/06-type-conversions/1-primitive-conversions-questions/solution.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ true + false = 1
1414
" -9 " - 5 = -14 // (4)
1515
null + 1 = 1 // (5)
1616
undefined + 1 = NaN // (6)
17+
" \t \n" - 2 = -2 // (7)
1718
```
1819
1. علامت جمع همراه با string `"" + 1` عدد `1` را به string تبدیل می‌کند: `"" + 1 = "1"` ، و سپس داریم: `"1" + 0` که همین قاعده برای آن نیز برقرار خواهد بود.
1920
2. علامت تفریق (مانند اکثر عملگرهای ریاضیاتی) فقط با اعداد کار می‌کند. این عملگر string خالی را به `0` تبدیل می‌کند.
2021
3. علامت جمع به همراه string ، باعث تبدیل عدد `5` به string و سپس چسباندن آن بهم می‌شود.
2122
4. علامت تفریق همیشه مقدار را به عدد تبدیل می‌کند. در نتیجه `" -9 "` را به عدد `–9` تبدیل می‌کند (فاصله‌های خالی را نیز حذف می‌کند).
2223
5. `null` پس از تبدیل به عدد `0` خواهد بود.
23-
6. `undefined` پس از تبدیل به عدد `NaN` خواهد بود.
24-
24+
6. `undefined` پس از تبدیل به عدد `NaN` خواهد بود.

1-js/02-first-steps/06-type-conversions/1-primitive-conversions-questions/task.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ true + false
2121
" -9 " - 5
2222
null + 1
2323
undefined + 1
24+
" \t \n" - 2
2425
```
2526

2627
به خوبی روی آن فکر کنید، بنویسید و با پاسخ‌ها مقایسه کنید.

1-js/02-first-steps/12-while-for/article.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,8 @@ Let's examine the `for` statement part-by-part:
108108
|-------|----------|----------------------------------------------------------------------------|
109109
| begin | `i = 0` | Executes once upon entering the loop. |
110110
| condition | `i < 3`| Checked before every loop iteration. If false, the loop stops. |
111-
| step| `i++` | Executes after the body on each iteration but before the condition check. |
112111
| body | `alert(i)`| Runs again and again while the condition is truthy. |
112+
| step| `i++` | Executes after the body on each iteration. |
113113

114114
The general loop algorithm works like this:
115115

@@ -300,7 +300,7 @@ This is just another reason not to use the question mark operator `?` instead of
300300

301301
Sometimes we need to break out from multiple nested loops at once.
302302

303-
For example, in the code below we loop over `i` and `j`, prompting for the coordinates `(i, j)` from `(0,0)` to `(3,3)`:
303+
For example, in the code below we loop over `i` and `j`, prompting for the coordinates `(i, j)` from `(0,0)` to `(2,2)`:
304304

305305
```js run no-beautify
306306
for (let i = 0; i < 3; i++) {

1-js/03-code-quality/03-comments/article.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,6 @@ Good comments allow us to maintain the code well, come back to it after a delay
175175
**Avoid comments:**
176176

177177
- That tell "how code works" and "what it does".
178-
- Put them only if it's impossible to make the code so simple and self-descriptive that it doesn't require those.
178+
- Put them in only if it's impossible to make the code so simple and self-descriptive that it doesn't require them.
179179

180180
Comments are also used for auto-documenting tools like JSDoc3: they read them and generate HTML-docs (or docs in another format).

1-js/03-code-quality/06-polyfills/article.md

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,20 @@ Here Babel comes to the rescue.
1919

2020
Actually, there are two parts in Babel:
2121

22-
1. First, the transpiler program, which rewrites the code. The developer runs it on their own computer. It rewrites the code into the older standard. And then the code is delivered to the website for users. Modern project build system like [webpack](http://webpack.github.io/) or [brunch](http://brunch.io/) provide means to run transpiler automatically on every code change, so that doesn't involve any time loss from our side.
22+
1. First, the transpiler program, which rewrites the code. The developer runs it on their own computer. It rewrites the code into the older standard. And then the code is delivered to the website for users. Modern project build systems like [webpack](http://webpack.github.io/) provide means to run transpiler automatically on every code change, so that very easy to integrate into development process.
2323

2424
2. Second, the polyfill.
2525

26-
The transpiler rewrites the code, so syntax features are covered. But for new functions we need to write a special script that implements them. JavaScript is a highly dynamic language, scripts may not just add new functions, but also modify built-in ones, so that they behave according to the modern standard.
26+
New language features may include new built-in functions and syntax constructs.
27+
The transpiler rewrites the code, transforming syntax constructs into older ones. But as for new built-in functions, we need to implement them. JavaScript is a highly dynamic language, scripts may add/modify any functions, so that they behave according to the modern standard.
2728

28-
There's a term "polyfill" for scripts that "fill in" the gap and add missing implementations.
29+
A script that updates/adds new functions is called "polyfill". It "fills in" the gap and adds missing implementations.
2930

3031
Two interesting polyfills are:
3132
- [core js](https://github.com/zloirock/core-js) that supports a lot, allows to include only needed features.
3233
- [polyfill.io](http://polyfill.io) service that provides a script with polyfills, depending on the features and user's browser.
3334

34-
So, we need to setup the transpiler and add the polyfill for old engines to support modern features.
35-
36-
If we orient towards modern engines and do not use features except those supported everywhere, then we don't need to use Babel.
35+
So, if we're going to use modern language features, a transpiler and a polyfill are necessary.
3736

3837
## Examples in the tutorial
3938

@@ -49,9 +48,7 @@ Examples that use modern JS will work only if your browser supports it.
4948
````
5049

5150
```offline
52-
As you're reading the offline version, examples are not runnable. But they usually work :)
51+
As you're reading the offline version, in PDF examples are not runnable. In EPUB some of them can run.
5352
```
5453

55-
[Chrome Canary](https://www.google.com/chrome/browser/canary.html) is good for all examples, but other modern browsers are mostly fine too.
56-
57-
Note that on production we can use Babel to translate the code into suitable for less recent browsers, so there will be no such limitation, the code will run everywhere.
54+
Google Chrome is usually the most up-to-date with language features, good to run bleeding-edge demos without any transpilers, but other modern browsers also work fine.
Lines changed: 1 addition & 1 deletion
Loading

1-js/04-object-basics/06-constructor-new/article.md

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ alert(user.name); // Jack
2727
alert(user.isAdmin); // false
2828
```
2929

30-
When a function is executed as `new User(...)`, it does the following steps:
30+
When a function is executed with `new`, it does the following steps:
3131

3232
1. A new empty object is created and assigned to `this`.
3333
2. The function body executes. Usually it modifies `this`, adds new properties to it.
@@ -51,7 +51,7 @@ function User(name) {
5151
}
5252
```
5353

54-
So the result of `new User("Jack")` is the same object as:
54+
So `let user = new User("Jack")` gives the same result as:
5555

5656
```js
5757
let user = {
@@ -146,10 +146,10 @@ function BigUser() {
146146

147147
this.name = "John";
148148

149-
return { name: "Godzilla" }; // <-- returns an object
149+
return { name: "Godzilla" }; // <-- returns this object
150150
}
151151

152-
alert( new BigUser().name ); // Godzilla, got that object ^^
152+
alert( new BigUser().name ); // Godzilla, got that object
153153
```
154154

155155
And here's an example with an empty `return` (or we could place a primitive after it, doesn't matter):
@@ -159,10 +159,7 @@ function SmallUser() {
159159

160160
this.name = "John";
161161

162-
return; // finishes the execution, returns this
163-
164-
// ...
165-
162+
return; // <-- returns this
166163
}
167164

168165
alert( new SmallUser().name ); // John
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
function Calculator() {
22

3-
let methods = {
3+
this.methods = {
44
"-": (a, b) => a - b,
55
"+": (a, b) => a + b
66
};
@@ -12,14 +12,14 @@ function Calculator() {
1212
op = split[1],
1313
b = +split[2]
1414

15-
if (!methods[op] || isNaN(a) || isNaN(b)) {
15+
if (!this.methods[op] || isNaN(a) || isNaN(b)) {
1616
return NaN;
1717
}
1818

19-
return methods[op](a, b);
19+
return this.methods[op](a, b);
2020
}
2121

2222
this.addMethod = function(name, func) {
23-
methods[name] = func;
23+
this.methods[name] = func;
2424
};
2525
}
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11

2-
- Please note how methods are stored. They are simply added to the internal object.
2+
- Please note how methods are stored. They are simply added to `this.methods` property.
33
- All tests and numeric conversions are done in the `calculate` method. In future it may be extended to support more complex expressions.
4+
5+
[js src="_js/solution.js"]

1-js/05-data-types/05-array-methods/6-calculator-extendable/task.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,6 @@ The task consists of two parts.
3131
alert( result ); // 8
3232
```
3333

34-
- No brackets or complex expressions in this task.
34+
- No parentheses or complex expressions in this task.
3535
- The numbers and the operator are delimited with exactly one space.
3636
- There may be error handling if you'd like to add it.

0 commit comments

Comments
 (0)