Skip to content

Commit f3aae90

Browse files
authored
Small language improvements
1 parent 2a3182a commit f3aae90

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

6-async/01-callbacks/article.md

+8-8
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
# Introduction: callbacks
44

5-
Many actions in Javascript are *asynchronous*.
5+
Many actions in JavaScript are *asynchronous*.
66

77
For instance, take a look at the function `loadScript(src)`:
88

@@ -23,7 +23,7 @@ We can use it like this:
2323
loadScript('/my/script.js');
2424
```
2525

26-
The function is called "asynchronous", because the action (script loading) finishes not now, but later.
26+
The function is called "asynchronously", because the action (script loading) finishes not now, but later.
2727

2828
The call initiates the script loading, then the execution continues. While the script is loading, the code below may finish executing, and if the loading takes time, other scripts may run meanwhile too.
2929

@@ -35,7 +35,7 @@ loadScript('/my/script.js');
3535

3636
Now let's say we want to use the new script when it loads. It probably declares new functions, so we'd like to run them.
3737

38-
...But if we do that immediately after the `loadScript(…)` call, that wouldn't work:
38+
But if we do that immediately after the `loadScript(…)` call, that wouldn't work:
3939

4040
```js
4141
loadScript('/my/script.js'); // the script has "function newFunction() {…}"
@@ -45,7 +45,7 @@ newFunction(); // no such function!
4545
*/!*
4646
```
4747

48-
Naturally, the browser probably didn't have time to load the script. So the immediate call to the new function fails. As of now, `loadScript` function doesn't provide a way to track the load completion. The script loads and eventually runs, that's all. But we'd like to know when happens, to use new functions and variables from that script.
48+
Naturally, the browser probably didn't have time to load the script. So the immediate call to the new function fails. As of now, `loadScript` function doesn't provide a way to track the load completion. The script loads and eventually runs, that's all. But we'd like to know when it happens, to use new functions and variables from that script.
4949

5050
Let's add a `callback` function as a second argument to `loadScript` that should execute when the script loads:
5151

@@ -118,7 +118,7 @@ loadScript('/my/script.js', function(script) {
118118

119119
After the outer `loadScript` is complete, the callback initiates the inner one.
120120

121-
...What if we want one more script?
121+
What if we want one more script...?
122122

123123
```js
124124
loadScript('/my/script.js', function(script) {
@@ -183,7 +183,7 @@ So the single `callback` function is used both for reporting errors and passing
183183

184184
From the first look it's a viable way of asynchronous coding. And indeed it is. For one or maybe two nested calls it looks fine.
185185

186-
But for multiple asynchronous actions that follow one after another we'll have a code like this:
186+
But for multiple asynchronous actions that follow one after another we'll have code like this:
187187

188188
```js
189189
loadScript('1.js', function(error, script) {
@@ -264,8 +264,8 @@ See? It does the same, and there's no deep nesting now, because we made every ac
264264

265265
It works, but the code looks like a torn apart spreadsheet. It's difficult to read, you probably noticed that. One needs to eye-jump between pieces while reading it. That's inconvenient, especially the reader is not familiar with the code and doesn't know where to eye-jump.
266266

267-
Also the functions named `step*` are all of a single use, they are created only to evade the "pyramid of doom". No one is going to reuse them outside of the action chain. So there's a bit of a namespace cluttering here.
267+
Also the functions named `step*` are all of a single use, they are created only to avoid the "pyramid of doom". No one is going to reuse them outside of the action chain. So there's a bit of a namespace cluttering here.
268268

269269
We'd like to have a something better.
270270

271-
Luckily, there are other ways to evade such pyramids. One of the best ways is to use "promises", described in the next chapter.
271+
Luckily, there are other ways to avoid such pyramids. One of the best ways is to use "promises", described in the next chapter.

0 commit comments

Comments
 (0)