Java Reference
In-Depth Information
var rainbow : String[] = [
"red", "orange", "yellow", "green", "blue", "violet"
] on replace oldRainbow
{
print("old rainbow: "); println(oldRainbow);
print("new rainbow: "); println(rainbow);
};
insert "indigo" after rainbow[4];
delete "violet" from rainbow;
insert "purple" into rainbow;
The output of this code is as follows:
old rainbow: [ ]
new rainbow: [ red, orange, yellow, green, blue, violet ]
old rainbow: [ red, orange, yellow, green, blue, violet ]
new rainbow: [ red, orange, yellow, green, blue, indigo,
violet ]
old rainbow: [ red, orange, yellow, green, blue, indigo,
violet ]
new rainbow: [ red, orange, yellow, green, blue, indigo ]
old rainbow: [ red, orange, yellow, green, blue, indigo ]
new rainbow: [ red, orange, yellow, green, blue, indigo,
purple ]
Be Careful When Using Bind/Triggers on Local
Va r i a b l e s
When using bind/triggers on local variables, you may come across a situation
where the variable is out of scope, yet the trigger still exists. To demonstrate, let's
look at the following pseudo code:
function doit() {
var result = SomeAsynchronousFunction { ... };
var myInput = bind result.data on replace {
…
};
}
A call to the SomeAsynchronousFunction() will set the result object's data
instance variable. Because, as its name implies, the function is asynchronous,
there's a good chance that by the time SomeAsynchronousFunction() returns, the
local variable myInput will be out of scope. So what happens here? Theoretically,
the bind and trigger should cease to exist after the variable is out of scope. In real-
ity, however, the trigger keeps on working until the variable has been garbage col-
lected. Quite a few already have been bitten by this problem, which is difficult to
debug. If at all possible, avoid such a construct.
Search WWH ::




Custom Search