Java Reference
In-Depth Information
print("origin2D properties:");
for(var x in origin2D) {
print(x);
}
After creating: Point(0, 0)
After changing x and y: Point(0, 0)
origin2D instanceof Point = true
origin2D properties:
toString
distance
Binding Object Properties
Nashorn lets you bind properties of one object to another object using the
Object.bindProperties(target, source) method where target is the object whose
properties will be bound to the properties of source . Listing 4-14 shows how to bind
properties of one object to another object.
Listing 4-14. Binding Properties of One Object to Another Object
// bindproperties.js
var trg = {};
var src = {x:100, y:200, z:300};
// Bind properties of sourceObject to targetObject
Object.bindProperties(trg, src);
// Print properties using trg
printf("trg-1: x=%d, y=%d,z=%d", trg.x, trg.y, trg.z);
// Now change z using trg
trg.z = 30; // Using src.z = 30 will have the same efect
// Print the properties using both objects and both
// should have the new value of z as 30
printf("trg-2: x=%d, y=%d,z=%d", trg.x, trg.y, trg.z);
printf("src-2: x=%d, y=%d,z=%d", src.x, src.y, src.z);
// Now add a new property to trg
trg.u = 30;
 
Search WWH ::




Custom Search