Skip to content

Commit 1b03278

Browse files
committed
minor
1 parent 011d72b commit 1b03278

File tree

6 files changed

+30
-3
lines changed

6 files changed

+30
-3
lines changed

2-ui/1-document/01-browser-environment/article.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ alert(window.innerHeight); // some number
3535

3636
## Document Object Model (DOM)
3737

38-
The `document` object gives access to a page contents. We can change or create literally anything.
38+
The `document` object gives access to the page content. We can change or create literally anything.
3939

4040
For instance:
4141
```js run

8-async/01-callback-hell/article.md

+29-2
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,39 @@ Many things that we do in JavaScript are asynchronous. We initiate a process, bu
55

66
The most obvious example is `setTimeout`, but there are others, like making network requests, performing animations and so on.
77

8-
Let's see a couple of examples, so that we can discover a problem, and then solve it using "promises".
9-
108
[cut]
119

1210
## Callbacks
1311

12+
Consider a function `loadScript` that loads a script:
13+
14+
```js
15+
function loadScript(src) {
16+
let script = document.createElement('script');
17+
script.src = src;
18+
}
19+
```
20+
21+
When the `<script>` tag is created and `src` is assigned, the browser loads the script and executes it. So, the function works. We can use it like this:
22+
23+
```js
24+
loadScript('/my/script.js');
25+
```
26+
27+
The function is asynchronous: the script starts loading now, but finishes later, maybe after a few seconds. So, the question is: how can we track the load end? As of now, the function provides no such way.
28+
29+
We'd like to invoke our code after the script is loaded. One of the easiest ways is to add a second argument to `loadScript`: the function that would run on load end.
30+
31+
32+
How can hook on "load completion"?
33+
34+
35+
From ancient times, Javascript allowed to use callback functions for asynchronous
36+
Most asychronous
37+
In this chapter we cover how to write callback-based asynchronous code.
38+
Let's see a couple of examples, so that we can discover a problem, and then solve it using "promises".
39+
40+
1441
Remember resource load/error events? They are covered in the chapter <info:onload-onerror>.
1542

1643
Let's say we want to create a function `loadScript` that loads a script and executes our code afterwards.

0 commit comments

Comments
 (0)