From 204137f9ca7191a338b36e977a52e4c7300cbaaa Mon Sep 17 00:00:00 2001 From: trbrc Date: Fri, 17 May 2019 13:19:51 +0200 Subject: [PATCH] Docs: Exporting function expression vs declaration Current docs give the impression that functions can not be default values for props. Suggestion to make the distinction between expressions and declarations clearer. --- site/content/docs/01-component-format.md | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/site/content/docs/01-component-format.md b/site/content/docs/01-component-format.md index 1472ff3d6c..ddd2667075 100644 --- a/site/content/docs/01-component-format.md +++ b/site/content/docs/01-component-format.md @@ -47,11 +47,14 @@ Svelte uses the `export` keyword to mark a variable declaration as a *property* // Values that are passed in as props // are immediately available console.log(foo, bar); - - // function declarations cannot be set externally, - // but can be accessed from outside - export function instanceMethod() { - alert(foo); + + // Function expressions can also be props + export let format = (number) => (number.toFixed(2)); + + // Function declarations are added as methods + // on the component, rather than props + export function greetMethod() { + alert(`I'm a <${this.constructor.name}>!`); } // you can also use export { ... as ... } to have