-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Open
Labels
Description
Hi there! I found the example of passing state into functions a bit complicated and unclear. It might help to simplify the explanation or break it down into smaller steps. I'd really appreciate it!
now:
https://svelte.dev/docs/svelte/$state#Passing-state-into-functions
function add(getA: () => number, getB: () => number) {
return () => getA() + getB();
}
let a = 1;
let b = 2;
let total = add(() => a, () => b);
console.log(total()); // 3
a = 3;
b = 4;
console.log(total()); // 7suggested:
function add(a: number, b: number) {
return a + b;
}
let a = 1;
let b = 2;
function total() {
return add(a, b);
}
console.log(total()); // 3
a = 3;
b = 4;
console.log(total()); // 7or even :
<script lang="ts">
const add = (a: number, b: number) => a + b;
let a = 1;
let b = 2;
const total = () => add(a, b);
console.log(total()); // 3
a = 3;
b = 4;
console.log(total()); // 7
</script>For the 3 versions i see the same result !