Skip to content

Commit 04162b9

Browse files
authored
Merge pull request #2944 from sveltejs/component-binding-example
Fix component binding example
2 parents a5cdc13 + f65379f commit 04162b9

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

site/content/docs/02-template-syntax.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -593,12 +593,12 @@ You can bind to component props using the same mechanism.
593593

594594
Components also support `bind:this`, allowing you to interact with component instances programmatically.
595595

596-
> Note that we can do `{cart.empty}` rather than `{() => cart.empty()}`, since component methods are closures. You don't need to worry about the value of `this` when calling them.
596+
> Note that we can't do `{cart.empty}` since `cart` is `undefined` when the button is first rendered and throws an error.
597597
598598
```html
599599
<ShoppingCart bind:this={cart}/>
600600

601-
<button on:click={cart.empty}>
601+
<button on:click={() => cart.empty()}>
602602
Empty shopping cart
603603
</button>
604604
```
@@ -1325,4 +1325,4 @@ It accepts a comma-separated list of variable names (not arbitrary expressions).
13251325
{@debug typeof user === 'object'}
13261326
```
13271327

1328-
The `{@debug}` tag without any arguments will insert a `debugger` statement that gets triggered when *any* state changes, as opposed to the specified variables.
1328+
The `{@debug}` tag without any arguments will insert a `debugger` statement that gets triggered when *any* state changes, as opposed to the specified variables.

0 commit comments

Comments
 (0)