0
0
mirror of https://github.com/sveltejs/svelte.git synced 2024-12-01 17:30:59 +01:00

Merge pull request #2794 from trbrc/patch-1

Docs: Exporting function expression vs declaration
This commit is contained in:
Rich Harris 2019-05-20 21:14:03 -04:00 committed by GitHub
commit 9ba91ddcaa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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 expressions can also be props
export let format = (number) => (number.toFixed(2));
// function declarations cannot be set externally,
// but can be accessed from outside
export function instanceMethod() {
alert(foo);
// 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