[TIMOB-4818] JavaScript prototypes doesn't work with Titanium components
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | Critical |
Status | Closed |
Resolution | Won't Fix |
Resolution Date | 2017-07-25T22:42:12.000+0000 |
Affected Version/s | n/a |
Fix Version/s | n/a |
Components | Android |
Labels | n/a |
Reporter | Ivan Skugor |
Assignee | Ingo Muschenetz |
Created | 2011-07-13T01:09:18.000+0000 |
Updated | 2017-07-25T22:42:12.000+0000 |
Description
Hi.
I've noticed that there is a bug when creating Titanium components with configuration objects that have properties defined in prototype chain. Here is example that demonstrate bug:
var win = Ti.UI.createWindow({
backgroundColor: '#fff'
});
var Conf = function() {
this.height = 50;
};
Conf.prototype.width = 100;
var cnf = new Conf();
cnf.backgroundColor = '#f93';
Ti.API.debug(cnf);
Ti.API.debug(cnf.width);
Ti.API.debug(cnf.height);
Ti.API.debug(cnf.backgroundColor);
//workaround is to copy properties from prototype chain
//cnf.width = cnf.width;
var view = Ti.UI.createView(cnf);
win.add(view);
win.open();
Output:
D/TiAPI ( 268): (kroll$1: app://app.js) [82,1429] {"backgroundColor":"#f93","height":50}
D/TiAPI ( 268): (kroll$1: app://app.js) [2,1431] 100.0
D/TiAPI ( 268): (kroll$1: app://app.js) [1,1432] 50.0
D/TiAPI ( 268): (kroll$1: app://app.js) [1,1433] #f93
So, as you can see, "width" property is defined in prototype chain and it exists if we try to access it. But, "View" component created with this configuration object hasn't width defined as it is defined in prototype chain, as you can see if you run the code.
Reassigning tickets, as per Tony Guntharp's request
Just to add, a workaround is to copy properties from object's prototype chain like this:
and pass that object to Titanium factory methods. I think this should be easy to fix for someone who knows where to fix. I think somewhere here the fix should go: https://github.com/appcelerator/titanium_mobile/tree/master/android/runtime/common/src/js in "invoker.js", but not sure. I know that this is trivial issue and that currently there are not much interested people that watches it, but JS prototypes are basic language feature and because of that I hope someone will find some time to fix this. :) Thanks.
Closing due to inactivity. If this issue still exists, please raise a new ticket.