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.
pull/2794/head
trbrc 5 years ago committed by GitHub
parent 298ae8ec23
commit c15d7ea2e1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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

Loading…
Cancel
Save