Using Nasal functions: Difference between revisions

Jump to navigation Jump to search
m
→‎Simple examples: http://forum.flightgear.org/viewtopic.php?f=30&t=28660&p=274634&hilit=spaghetti#p274625
m (todo: should probably introduce anonymous/unnamed functions first (retained scope, closures))
m (→‎Simple examples: http://forum.flightgear.org/viewtopic.php?f=30&t=28660&p=274634&hilit=spaghetti#p274625)
Line 34: Line 34:


== Simple examples ==
== Simple examples ==
{{Note|if you don't understand nested (anonymous) functions yet, use explicit function names:
<syntaxhighlight lang="nasal">
var myFunction = func() {
print("Hello World!");
}
myFunction ();
</syntaxhighlight>
The main difference being that the invocation of the myFunction function can be replaced with the anonymous function body, i.e. without any function name associated with it.}}


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''':

Navigation menu