Skip to content

Commit 7d6d436

Browse files
committed
minor
1 parent 3ce2d96 commit 7d6d436

File tree

5 files changed

+34
-28
lines changed

5 files changed

+34
-28
lines changed

1-js/11-async/06-promisify/article.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Promisification -- is a long word for a simple transform. It's conversion of a function that accepts a callback into a function returning a promise.
44

5-
In other words, we create a wrapper-function that does the same, internally calling the original one, but returns a promise.
5+
To be more precise, we create a wrapper-function that does the same, internally calling the original one, but returns a promise.
66

77
Such transforms are often needed in real-life, as many functions and libraries are callback-based. But promises are more convenient. So it makes sense to promisify those.
88

@@ -105,7 +105,7 @@ f = promisify(f, true);
105105
f(...).then(arrayOfResults => ..., err => ...)
106106
```
107107
108-
In some cases, `err` may be absent at all: `callback(result)`, or there's something exotic in the callback format, then we can promisify such functions manually.
108+
In some cases, `err` may be absent at all: `callback(result)`, or there's something exotic in the callback format, then we can promisify such functions without using the helper, manually.
109109
110110
There are also modules with a bit more flexible promisification functions, e.g. [es6-promisify](https://github.com/digitaldesignlabs/es6-promisify). In Node.js, there's a built-in `util.promisify` function for that.
111111

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

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ A module usually contains a class or a library of useful functions.
66

77
For a long time, JavaScript existed without a language-level module syntax. That wasn't a problem, because initially scripts were small and simple. So there was no need.
88

9-
But eventually scripts became more and more complex, so the community invented a variety of ways to organize code into modules.
9+
But eventually scripts became more and more complex, so the community invented a variety of ways to organize code into modules, special libraries to load modules on demand.
1010

1111
For instance:
1212

@@ -20,9 +20,9 @@ Now all these slowly become a part of history, but we still can find them in old
2020

2121
A module is just a file, a single script, as simple as that.
2222

23-
Directives `export` and `import` allow to interchange functionality between modules:
23+
There are directives `export` and `import` to interchange functionality between modules, call functions of one module from another one:
2424

25-
- `export` keyword labels variables and functions that should be accessible from outside the file.
25+
- `export` keyword labels variables and functions that should be accessible from outside the current module.
2626
- `import` allows to import functionality from other modules.
2727

2828
For instance, if we have a file `sayHi.js` exporting a function:
@@ -44,13 +44,15 @@ alert(sayHi); // function...
4444
sayHi('John'); // Hello, John!
4545
```
4646

47-
In this tutorial we concentrate on the language itself, but we use browser as the demo environment, so let's see how modules work in the browser.
47+
In this tutorial we concentrate on the language itself, but we use browser as the demo environment, so let's see how to use modules in the browser.
4848

49-
To use modules, we must set the attribute `<script type="module">`, like this:
49+
As modules support special keywords and features, we must tell the browser that a script should be treated as module, by using the attribute `<script type="module">`.
50+
51+
Like this:
5052

5153
[codetabs src="say" height="140" current="index.html"]
5254

53-
The browser automatically fetches and evaluates imports, then runs the script.
55+
The browser automatically fetches and evaluates imported modules, and then runs the script.
5456

5557
## Core module features
5658

@@ -60,7 +62,7 @@ There are core features, valid both for browser and server-side JavaScript.
6062

6163
### Always "use strict"
6264

63-
Modules always `use strict`. E.g. assigning to an undeclared variable will give an error.
65+
Modules always `use strict`, by default. E.g. assigning to an undeclared variable will give an error.
6466

6567
```html run
6668
<script type="module">
@@ -101,7 +103,7 @@ In the browser, independent top-level scope also exists for each `<script type="
101103
</script>
102104
```
103105

104-
If we really need to make a "global" in-browser variable, we can explicitly assign it to `window` and access as `window.user`. But that's an exception requiring a good reason.
106+
If we really need to make a window-level global variable, we can explicitly assign it to `window` and access as `window.user`. But that's an exception requiring a good reason.
105107

106108
### A module code is evaluated only the first time when imported
107109

@@ -229,11 +231,11 @@ You may want skip those for now if you're reading for the first time, or if you
229231
Module scripts are *always* deferred, same effect as `defer` attribute (described in the chapter [](info:script-async-defer)), for both external and inline scripts.
230232
231233
In other words:
232-
- external module scripts `<script type="module" src="...">` don't block HTML processing.
233-
- module scripts wait until the HTML document is fully ready.
234-
- relative order is maintained: scripts that go first in the document, execute first.
234+
- external module scripts `<script type="module" src="...">` don't block HTML processing, they load in parallel with other resources.
235+
- module scripts wait until the HTML document is fully ready (even if they are tiny and load faster than HTML), and then run.
236+
- relative order of scripts is maintained: scripts that go first in the document, execute first.
235237
236-
As a side-effect, module scripts always see HTML elements below them.
238+
As a side-effect, module scripts always "see" the fully loaded HTML-page, including HTML elements below them.
237239
238240
For instance:
239241
@@ -245,6 +247,8 @@ For instance:
245247
// as modules are deferred, the script runs after the whole page is loaded
246248
</script>
247249
250+
Compare to regular script below:
251+
248252
<script>
249253
*!*
250254
alert(typeof button); // Error: button is undefined, the script can't see elements below
@@ -259,7 +263,7 @@ Please note: the second script actually works before the first! So we'll see `un
259263
260264
That's because modules are deferred, so way wait for the document to be processed. The regular scripts runs immediately, so we saw its output first.
261265
262-
When using modules, we should be aware that HTML-document can show up before the JavaScript application is ready. Some functionality may not work yet. We should put transparent overlays or "loading indicators", or otherwise ensure that the visitor won't be confused because of it.
266+
When using modules, we should be aware that HTML-page shows up as it loads, and JavaScript modules run after that, so the user may see the page before the JavaScript application is ready. Some functionality may not work yet. We should put transparent overlays or "loading indicators", or otherwise ensure that the visitor won't be confused by that.
263267
264268
### Async works on inline scripts
265269
@@ -303,15 +307,15 @@ There are two notable differences of external module scripts:
303307
304308
### No "bare" modules allowed
305309
306-
In the browser, in scripts (not in HTML), `import` must get either a relative or absolute URL. Modules without any path are called "bare" modules. Such modules are not allowed in `import`.
310+
In the browser, `import` must get either a relative or absolute URL. Modules without any path are called "bare" modules. Such modules are not allowed in `import`.
307311
308312
For instance, this `import` is invalid:
309313
```js
310314
import {sayHi} from 'sayHi'; // Error, "bare" module
311315
// the module must have a path, e.g. './sayHi.js' or wherever the module is
312316
```
313317
314-
Certain environments, like Node.js or bundle tools allow bare modules, as they have own ways for finding modules and hooks to fine-tune them. But browsers do not support bare modules yet.
318+
Certain environments, like Node.js or bundle tools allow bare modules, without any path, as they have own ways for finding modules and hooks to fine-tune them. But browsers do not support bare modules yet.
315319
316320
### Compatibility, "nomodule"
317321
@@ -362,7 +366,7 @@ To summarize, the core concepts are:
362366
1. A module is a file. To make `import/export` work, browsers need `<script type="module">`, that implies several differences:
363367
- Deferred by default.
364368
- Async works on inline scripts.
365-
- External scripts need CORS headers.
369+
- To load external scripts from another origin (domain/protocol/port), CORS headers are needed.
366370
- Duplicate external scripts are ignored.
367371
2. Modules have their own, local top-level scope and interchange functionality via `import/export`.
368372
3. Modules always `use strict`.
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
1. Yes, true. The element `elem.lastChild` is always the last one, it has no `nextSibling`, so if there are children, then yes.
2-
2. No, wrong, because `elem.children[0]` is the first child among elements. But there may be non-element nodes before it. So `previousSibling` may be a text node.
1+
1. Yes, true. The element `elem.lastChild` is always the last one, it has no `nextSibling`.
2+
2. No, wrong, because `elem.children[0]` is the first child *among elements*. But there may exist non-element nodes before it. So `previousSibling` may be a text node. Also, if there are no children, then trying to access `elem.children[0]`
33

4-
Please note that for both cases if there are no children, then there will be an error. For instance, if `elem.lastChild` is `null`, we can't access `elem.lastChild.nextSibling`.
4+
Please note: for both cases if there are no children, then there will be an error.
5+
6+
If there are no children, `elem.lastChild` is `null`, so we can't access `elem.lastChild.nextSibling`. And the collection `elem.children` is empty (like an empty array `[]`).

2-ui/1-document/03-dom-navigation/article.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ libs:
77

88
# Walking the DOM
99

10-
The DOM allows us to do anything with elements and their contents, but first we need to reach the corresponding DOM object, get it into a variable, and then we are able to modify it.
10+
The DOM allows us to do anything with elements and their contents, but first we need to reach the corresponding DOM object.
1111

1212
All operations on the DOM start with the `document` object. From it we can access any node.
1313

@@ -86,7 +86,7 @@ For instance, here `<body>` has children `<div>` and `<ul>` (and few blank text
8686
</html>
8787
```
8888
89-
...And if we ask for all descendants of `<body>`, then we get direct children `<div>`, `<ul>` and also more nested elements like `<li>` (being a child of `<ul>`) and `<b>` (being a child of `<li>`) -- the entire subtree.
89+
...And all descendants of `<body>` are not only direct children `<div>`, `<ul>` but also more deeply nested elements, such as `<li>` (a child of `<ul>`) and `<b>` (a child of `<li>`) -- the entire subtree.
9090
9191
**The `childNodes` collection provides access to all child nodes, including text nodes.**
9292

9-regular-expressions/21-regexp-unicode-properties/article.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ alert("color: #123ABC".match(reg)); // 123ABC
4747

4848
There are also properties with a value. For instance, Unicode "Script" (a writing system) can be Cyrillic, Greek, Arabic, Han (Chinese) etc, the [list is long]("https://en.wikipedia.org/wiki/Script_(Unicode)").
4949

50-
To search for certain scripts, we should supply `Script=<value>`, e.g. to search for cyrillic letters: `\p{sc=Cyrillic}`, for Chinese glyphs: `\p{sc=Han}`, etc:
50+
To search for characters in certain scripts ("alphabets"), we should supply `Script=<value>`, e.g. to search for cyrillic letters: `\p{sc=Cyrillic}`, for Chinese glyphs: `\p{sc=Han}`, etc:
5151

5252
```js run
5353
let regexp = /\p{sc=Han}+/gu; // get chinese words
@@ -59,15 +59,15 @@ alert( str.match(regexp) ); // 你好
5959

6060
## Building multi-language \w
6161

62-
Let's make a "universal" regexp for `pattern:\w`, for any language. That task has a standard solution in many programming languages with unicode-aware regexps, e.g. Perl.
62+
The pattern `pattern:\w` means "wordly characters", but doesn't work for languages that use non-Latin alphabets, such as Cyrillic and others. It's just a shorthand for `[a-zA-Z0-9_]`, so `pattern:\w+` won't find any Chinese words etc.
63+
64+
Let's make a "universal" regexp, that looks for wordly characters in any language. That's easy to do using Unicode properties:
6365

6466
```js
6567
/[\p{Alphabetic}\p{Mark}\p{Decimal_Number}\p{Connector_Punctuation}\p{Join_Control}]/u
6668
```
6769

68-
Let's decipher. Remember, `pattern:\w` is actually the same as `pattern:[a-zA-Z0-9_]`.
69-
70-
So the character set includes:
70+
Let's decipher. Just as `pattern:\w` is the same as `pattern:[a-zA-Z0-9_]`, we're making a set of our own, that includes:
7171

7272
- `Alphabetic` for letters,
7373
- `Mark` for accents, as in Unicode accents may be represented by separate code points,

0 commit comments

Comments
 (0)