Move function declaration before reference

The way the example is currently presented requires that the user have an understanding of how Javascript hoists functions. By moving the function declaration before the function reference, the order of the code becomes more clear to the reader, which I think is valuable here. I think it's more important that this material clearly teach the behavior of Svelte, rather than the nuances of Javascript.
pull/5491/head
Daniel Power 5 years ago
parent 377c7647ed
commit 39341bbfdf

@ -1,6 +1,4 @@
<script>
let promise = getRandomNumber();
async function getRandomNumber() {
const res = await fetch(`tutorial/random-number`);
const text = await res.text();
@ -12,6 +10,8 @@
}
}
let promise = getRandomNumber();
function handleClick() {
promise = getRandomNumber();
}

@ -1,6 +1,4 @@
<script>
let promise = getRandomNumber();
async function getRandomNumber() {
const res = await fetch(`tutorial/random-number`);
const text = await res.text();
@ -12,6 +10,8 @@
}
}
let promise = getRandomNumber();
function handleClick() {
promise = getRandomNumber();
}

Loading…
Cancel
Save