Java Reference
In-Depth Information
There's more...
There are couple more features about functions in which you may be interested.
Bound functions
Since a function is a considered to be an expression in JavaFX, it can be bound to a variable
(similar to a code block binding, see Using Binding and Triggers to Update Variables ).
var f = 10;
bound function increaseIt(a:Number):Number {
a + f;
}
var x = 5;
def y = bind increaseIt(x);
When a function is defined as being bound, any change to values inside the function block
(including its parameters) will cause an update to the binding variable. Here, whenever
variable f or x changes, the value of y is updated automatically.
The run() function
JavaFX offers a way to define a script file's main-entry-point using the special script-level
function run() . If you place the following in a script file:
function run() {
println ("I am always called!");
}
When you execute the script, the run() function will be executed as the starting point
of the script by the JavaFX runtime. This similar to having the public static void
main(String[] args) method in Java.
When you create a script file with script-level code without run() , the compiler creates one
for you and places your script's code inside of it. As such, your script seems to execute top to
bottom. However, when you provide your own run() , that is no longer the case. The JavaFX
runtime will only call whatever code is inside of the run() function.
See also
F Creating and using JavaFX classes
F Declaring and using variables in JavaFX
F Using binding and triggers to update variables
 
Search WWH ::




Custom Search