[AC-2245] Custom properties not passed by reference
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | n/a |
Status | Closed |
Resolution | Invalid |
Resolution Date | 2013-04-02T23:51:19.000+0000 |
Affected Version/s | n/a |
Fix Version/s | n/a |
Components | Titanium SDK & CLI |
Labels | n/a |
Reporter | Tristan Marly |
Assignee | Mauro Parra-Miranda |
Created | 2012-12-13T07:53:36.000+0000 |
Updated | 2016-03-08T07:41:14.000+0000 |
Description
I don't know if this is a bug or a weird behavior, but it seems that when creating some Ti.UI objects, custom properties are cloned and not passed by reference.
Here is a simple test case illustrating the pb:
var win = Ti.UI.createWindow({
layout: 'vertical',
});
var customPropertyValue = {text: "hello"};
// Build a table
var data = [
Ti.UI.createTableViewRow({
title: 'Row 1',
customProperty: customPropertyValue,
}),
];
var table = Ti.UI.createTableView({
data: data,
});
// Click events
table.addEventListener('click', function(e) {
Ti.API.info('Event ! text=' + e.rowData.customProperty.text);
});
win.add(table);
win.open();
// Modify the property
customPropertyValue.text = "bye";
As you can see, the customPropertyValue is modified at the end of the code. But when we later click on the row, the displayed message is "hello", and not "bye".
So at the step "build a table", it seems that the customPropertyValue is cloned.
For native components the properties are passed by value
Invalid issue.