20,741
edits
m (make example more explicit) |
|||
Line 26: | Line 26: | ||
== Simple examples == | == Simple examples == | ||
In its most basic form, a function does not even take any arguments. Let's imagine a function named '''hello''' | In its most basic form, a function does not even take any arguments. Let's imagine a function named '''hello''': | ||
<syntaxhighlight lang="nasal"> | |||
var hello = func() { | |||
print("Hello !"); | |||
}; | |||
</syntaxhighlight> | |||
Functions are typically called by appending parentheses to the function name, empty parentheses for function calls without any arguments. | |||
<syntaxhighlight lang="nasal"> | <syntaxhighlight lang="nasal"> | ||
Line 54: | Line 62: | ||
hello( "FlightGear" ); | hello( "FlightGear" ); | ||
</syntaxhighlight> | </syntaxhighlight> | ||
This passes a single function argument to the hello function. In our previous example, we simply used the return value of the first (inner) function call as the argument of the outer (second) call. | This passes a single function argument to the hello function. In our previous example, we simply used the return value of the first (inner) function call as the argument of the outer (second) call. | ||
Line 63: | Line 70: | ||
var hello = func( name ) { | var hello = func( name ) { | ||
print("Hello ", name); | print("Hello ", name); | ||
} | }; | ||
</syntaxhighlight> | </syntaxhighlight> | ||