Problem
If you add an object to a window (for example, a custom property "foo"), only the initial value of the property is used.
Sample Code
Drop this in an app.js and run it. No other interaction is required.
The following sample stores an object in two places -- the "foo" variable, and in win's "foo" property. The code below tests that both places are referring to the same object by doing a couple assignments. If everything goes well, an alert proclaiming: "PASS!" will show up. Otherwise, "FAIL:" will show up.
var win = Ti.UI.createWindow();
win.open();
// initialize
var foo = { bar: 'Assign1'};
// store it in window
win.foo = foo;
// reassign through the local object
foo.bar = 'Assign2';
// and then reassign through the window property
win.foo.bar = 'Assign3';
// now check the values
Ti.API.info('foo.bar = ' + foo.bar);
Ti.API.info('win.foo.bar = ' + win.foo.bar);
if (foo.bar != 'Assign3') {
alert('FAIL: foo.bar != "Assign3"');
}
else if (win.foo.bar != 'Assign3') {
alert('FAIL: win.foo.bar != "Assign3"');
}
else {
alert('PASS: All assignments looked good.');
}
Expected Behavior
Since we're dealing with a single object, and storing it in two locations, we should be able to change its properties in any of the places the reference is stored and get the updated value out.
Tested On
See "Environment".
Associated Helpdesk Ticket
http://appc.me/c/APP-744341
Duplicate of 2392. The issue is that proxy accessors are copy on read and copy on write (due to the nature of proxies storing properties in Objective C, not JS). As mentioned there, fixing will involve deep changes and possibly removing multi-contexts for JS. Very nontrivial.
Closing issue due to time passed and irrelevance of the ticket.