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:
commit
9ba91ddcaa
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user