You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: 6-async/01-callbacks/article.md
+4-3Lines changed: 4 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -29,7 +29,8 @@ The call initiates the script loading, then the execution continues. While the s
29
29
30
30
```js
31
31
loadScript('/my/script.js');
32
-
// the code below doesn't wait for the script loading to finish
32
+
// the code below loadScript doesn't wait for the script loading to finish
33
+
// ...
33
34
```
34
35
35
36
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.
@@ -44,7 +45,7 @@ newFunction(); // no such function!
44
45
*/!*
45
46
```
46
47
47
-
Naturally, the browser probably didn't have time to load the script. 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 happens, to use new functions and variables from that script.
48
49
49
50
Let's add a `callback` function as a second argument to `loadScript` that should execute when the script loads:
50
51
@@ -150,7 +151,7 @@ function loadScript(src, callback) {
0 commit comments