Skip to content

Commit e22e971

Browse files
committed
Merge branch 'refactor'
2 parents 184f7ae + 6fb4aab commit e22e971

File tree

374 files changed

+2835
-174
lines changed

Some content is hidden

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

374 files changed

+2835
-174
lines changed

1-js/02-first-steps/03-strict-mode/article.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ Even if we press `key:Shift+Enter` to input multiple lines, and put `use strict`
5757
5858
The reliable way to ensure `use strict` would be to input the code into console like this:
5959
60-
```
60+
```js
6161
(function() {
6262
'use strict';
6363
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
```js run no-beautify
2-
function sortByName(arr) {
2+
function sortByAge(arr) {
33
arr.sort((a, b) => a.age > b.age ? 1 : -1);
44
}
55

66
let john = { name: "John", age: 25 };
77
let pete = { name: "Pete", age: 30 };
88
let mary = { name: "Mary", age: 28 };
99

10-
let arr = [ john, pete, mary ];
10+
let arr = [ pete, john, mary ];
1111

12-
sortByName(arr);
12+
sortByAge(arr);
1313

1414
// now sorted is: [john, mary, pete]
1515
alert(arr[0].name); // John
16+
alert(arr[1].name); // Mary
1617
alert(arr[2].name); // Pete
1718
```

1-js/05-data-types/05-array-methods/8-sort-objects/task.md

+5-4
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ importance: 5
22

33
---
44

5-
# Sort objects
5+
# Sort users by age
66

7-
Write the function `sortByName(users)` that gets an array of objects with the `age` property and sorts them by `age`.
7+
Write the function `sortByAge(users)` that gets an array of objects with the `age` property and sorts them by `age`.
88

99
For instance:
1010

@@ -13,11 +13,12 @@ let john = { name: "John", age: 25 };
1313
let pete = { name: "Pete", age: 30 };
1414
let mary = { name: "Mary", age: 28 };
1515

16-
let arr = [ john, pete, mary ];
16+
let arr = [ pete, john, mary ];
1717

18-
sortByName(arr);
18+
sortByAge(arr);
1919

2020
// now: [john, mary, pete]
2121
alert(arr[0].name); // John
22+
alert(arr[1].name); // Mary
2223
alert(arr[2].name); // Pete
2324
```

1-js/06-advanced-functions/08-settimeout-setinterval/3-rewrite-settimeout/solution.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ let i = 0;
55

66
let start = Date.now();
77

8-
let timer = setInterval(count, 0);
8+
let timer = setInterval(count);
99

1010
function count() {
1111

@@ -20,4 +20,3 @@ function count() {
2020

2121
}
2222
```
23-

1-js/06-advanced-functions/08-settimeout-setinterval/3-rewrite-settimeout/task.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ function count() {
1818
if (i == 1000000000) {
1919
alert("Done in " + (Date.now() - start) + 'ms');
2020
} else {
21-
setTimeout(count, 0);
21+
setTimeout(count);
2222
}
2323

2424
// a piece of heavy job

1-js/06-advanced-functions/08-settimeout-setinterval/article.md

+11-11
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ These methods are not a part of JavaScript specification. But most environments
1515
The syntax:
1616

1717
```js
18-
let timerId = setTimeout(func|code, delay[, arg1, arg2...])
18+
let timerId = setTimeout(func|code, [delay], [arg1], [arg2], ...)
1919
```
2020

2121
Parameters:
@@ -25,7 +25,7 @@ Parameters:
2525
Usually, that's a function. For historical reasons, a string of code can be passed, but that's not recommended.
2626

2727
`delay`
28-
: The delay before run, in milliseconds (1000 ms = 1 second).
28+
: The delay before run, in milliseconds (1000 ms = 1 second), by default 0.
2929

3030
`arg1`, `arg2`...
3131
: Arguments for the function (not supported in IE9-)
@@ -110,7 +110,7 @@ For browsers, timers are described in the [timers section](https://www.w3.org/TR
110110
The `setInterval` method has the same syntax as `setTimeout`:
111111

112112
```js
113-
let timerId = setInterval(func|code, delay[, arg1, arg2...])
113+
let timerId = setInterval(func|code, [delay], [arg1], [arg2], ...)
114114
```
115115

116116
All arguments have the same meaning. But unlike `setTimeout` it runs the function not only once, but regularly after the given interval of time.
@@ -238,7 +238,7 @@ There's a side-effect. A function references the outer lexical environment, so,
238238

239239
## setTimeout(...,0)
240240

241-
There's a special use case: `setTimeout(func, 0)`.
241+
There's a special use case: `setTimeout(func, 0)`, or just `setTimeout(func)`.
242242

243243
This schedules the execution of `func` as soon as possible. But scheduler will invoke it only after the current code is complete.
244244

@@ -247,7 +247,7 @@ So the function is scheduled to run "right after" the current code. In other wor
247247
For instance, this outputs "Hello", then immediately "World":
248248

249249
```js run
250-
setTimeout(() => alert("World"), 0);
250+
setTimeout(() => alert("World"));
251251

252252
alert("Hello");
253253
```
@@ -260,7 +260,7 @@ There's a trick to split CPU-hungry tasks using `setTimeout`.
260260

261261
For instance, a syntax-highlighting script (used to colorize code examples on this page) is quite CPU-heavy. To highlight the code, it performs the analysis, creates many colored elements, adds them to the document -- for a big text that takes a lot. It may even cause the browser to "hang", which is unacceptable.
262262

263-
So we can split the long text into pieces. First 100 lines, then plan another 100 lines using `setTimeout(...,0)`, and so on.
263+
So we can split the long text into pieces. First 100 lines, then plan another 100 lines using `setTimeout(..., 0)`, and so on.
264264

265265
For clarity, let's take a simpler example for consideration. We have a function to count from `1` to `1000000000`.
266266

@@ -303,7 +303,7 @@ function count() {
303303
if (i == 1e9) {
304304
alert("Done in " + (Date.now() - start) + 'ms');
305305
} else {
306-
setTimeout(count, 0); // schedule the new call (**)
306+
setTimeout(count); // schedule the new call (**)
307307
}
308308

309309
}
@@ -338,7 +338,7 @@ function count() {
338338

339339
// move the scheduling at the beginning
340340
if (i < 1e9 - 1e6) {
341-
setTimeout(count, 0); // schedule the new call
341+
setTimeout(count); // schedule the new call
342342
}
343343

344344
do {
@@ -371,8 +371,8 @@ setTimeout(function run() {
371371
times.push(Date.now() - start); // remember delay from the previous call
372372
373373
if (start + 100 < Date.now()) alert(times); // show the delays after 100ms
374-
else setTimeout(run, 0); // else re-schedule
375-
}, 0);
374+
else setTimeout(run); // else re-schedule
375+
});
376376
377377
// an example of the output:
378378
// 1,1,1,1,9,15,20,24,30,35,40,45,50,55,59,64,70,75,80,85,90,95,100
@@ -430,7 +430,7 @@ And if we use `setTimeout` to split it into pieces then changes are applied in-b
430430
} while (i % 1e3 != 0);
431431
432432
if (i < 1e9) {
433-
setTimeout(count, 0);
433+
setTimeout(count);
434434
}
435435
436436
}

1-js/13-modules/01-modules-intro/article.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ You may want skip those for now if you're reading for the first time, or if you
226226
227227
### Module scripts are deferred
228228
229-
Module scripts are *always* deferred, same effect as `defer` attribute (described in the chapter [](info:onload-ondomcontentloaded)), for both external and inline scripts.
229+
Module scripts are *always* deferred, same effect as `defer` attribute (described in the chapter [](info:script-async-defer)), for both external and inline scripts.
230230
231231
In other words:
232232
- external module scripts `<script type="module" src="...">` don't block HTML processing.

0 commit comments

Comments
 (0)