Java Reference
In-Depth Information
var er2 = EmpRec {
label: "er2"
name: bind myName
id: myID
};
The second declaration shows how to bind an individual instance variable of an
object literal instead of the whole object. Specifically, name is bound to the exter-
nal variable myName . A change to the value of myName causes a recalculation of
the name variable without recreating the er2 object. As the id variable is
unbound, a change to the myID external variable will not cause any recalculation
at all. Instance variable binding is enabled by placing the bind keyword inside
the object literal on the instance variables of interest.
var er3 = bind EmpRec {
label: "er3"
name: bind myName
id: myID
};
The third declaration combines both whole object and instance variable binding.
In this scenario, variables that aren't specifically bound will, when a recalcula-
tion takes place, cause a new object to be created. If, on the other hand, an
instance variable is bound, a recalculation will update the variable without caus-
ing the object to be recreated. In effect, the instance variable bind trumps the
overall object literal bind. In the preceding declaration, any update to the myID
external variable will trigger an object recreation, whereas any update to myName
will cause a recalculation without object recreation. So fleshing this out a little
and executing the code snippet
var myName : String = "Jack";
var myID : Integer = 123;
var er1 = bind EmpRec {
label: "er1"
name: myName
id: myID
};
var er2 = EmpRec {
label: "er2"
name: bind myName
id: myID
};
var er3 = bind EmpRec {
label: "er3"
name: bind myName
id: myID
};
Search WWH ::




Custom Search