content improvements
This commit is contained in:
parent
2189dc9a4c
commit
e1c9b21d1f
1 changed files with 8 additions and 4 deletions
|
@ -2,10 +2,12 @@
|
|||
|
||||
# Introduction: callbacks
|
||||
|
||||
```warn header="We use browser methods here"
|
||||
To demonstrate the use of callbacks, promises and other abstract concepts, we'll be using some browser methods; specifically, loading scripts and performing simple document manipulations.
|
||||
```warn header="We use browser methods in examples here"
|
||||
To demonstrate the use of callbacks, promises and other abstract concepts, we'll be using some browser methods: specifically, loading scripts and performing simple document manipulations.
|
||||
|
||||
If you're not familiar with these methods, and their usage in the examples is confusing, or if you would just like to understand them better, you may want to read a few chapters from the [next part](/document) of the tutorial.
|
||||
If you're not familiar with these methods, and their usage in the examples is confusing, you may want to read a few chapters from the [next part](/document) of the tutorial.
|
||||
|
||||
Although, we'll try to make things clear anyway. There won't be anything really complex browser-wise.
|
||||
```
|
||||
|
||||
Many actions in JavaScript are *asynchronous*. In other words, we initiate them now, but they finish later.
|
||||
|
@ -18,13 +20,15 @@ Take a look at the function `loadScript(src)`, that loads a script with the give
|
|||
|
||||
```js
|
||||
function loadScript(src) {
|
||||
// creates a <script> tag and append it to the page
|
||||
// this causes the script with given src to start loading and run when complete
|
||||
let script = document.createElement('script');
|
||||
script.src = src;
|
||||
document.head.append(script);
|
||||
}
|
||||
```
|
||||
|
||||
It appends to the document the new, dynamically created, tag `<script src="…">`. The browser loads and executes it.
|
||||
It appends to the document the new, dynamically created, tag `<script src="…">` with given `src`. The browser automatically starts loading it and executes when complete.
|
||||
|
||||
We can use this function like this:
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue