Java Reference
In-Depth Information
The value of variable row is updated depending on the evaluation of the bound
conditional expression.
Row 0 is even
Row 1 is odd
Row 2 is even
Row 3 is odd
In the example, when the if statement evaluates to true, row is assigned "even", else it
receives "odd".
Binding to a code block
The code block binding lets developers create compound expressions to logically control how
the declared variable is updated.
var x = 2;
def xDoubled = bind {
var y = 2;
y * x;
x = 3;
println ( "X = 3, doubled = {xDoubled}");
x = 27;
println ( "x = 27, doubled = {xDoubled}");
When x is updated, the code block is re-evaluated, and xDoubled is updated with the new
value of the last expression in the block.
Be aware that assigning a code block to a variable without the bind
keyword is legal in JavaFX. So, make sure not to leave the bind
keyword out, as omitting it changes the meaning of the assignment,
and it will behave differently.
Binding to a function
JavaFX can bind a variable to a function call as well.
function squareIt(x):Number {
var param = 0;
def squared = bind squareIt(param);
param = 96;
println ("Param = {param}, squared = {squared}");
Search WWH ::

Custom Search