Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-4818] JavaScript prototypes doesn't work with Titanium components

GitHub Issuen/a
TypeBug
PriorityCritical
StatusClosed
ResolutionWon't Fix
Resolution Date2017-07-25T22:42:12.000+0000
Affected Version/sn/a
Fix Version/sn/a
ComponentsAndroid
Labelsn/a
ReporterIvan Skugor
AssigneeIngo Muschenetz
Created2011-07-13T01:09:18.000+0000
Updated2017-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.

Comments

  1. Paul Dowsett 2011-10-21

    Reassigning tickets, as per Tony Guntharp's request
  2. Ivan Skugor 2011-12-20

    Just to add, a workaround is to copy properties from object's prototype chain like this:
       for (var c in cnf) {
           cnf[c] = cnf[c];
       }
       
    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.
  3. Lee Morris 2017-07-25

    Closing due to inactivity. If this issue still exists, please raise a new ticket.

JSON Source