Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-5744] Android: Titanium objects' toString method is not consistent

GitHub Issuen/a
TypeBug
PriorityTrivial
StatusClosed
ResolutionWon't Fix
Resolution Date2020-02-14T09:15:57.000+0000
Affected Version/sRelease 1.7.3
Fix Version/sn/a
ComponentsAndroid
Labelsn/a
ReporterIvan Skugor
AssigneeRene Pot
Created2011-10-12T05:04:33.000+0000
Updated2020-02-14T09:15:57.000+0000

Description

As noticed in this thread: http://developer.appcelerator.com/question/126708/respond-to-a-button-in-a-table-row-without-triggering-table-row-click Titanium component's "toString" method does not provide identical string on different platforms. For example:
var button = Ti.UI.createButton();
Ti.API.debug(button.toString());
on Android it produces: [Ti.UI.Button] while on iOS it produces: [object TiUIButton] IMHO, it would be nice if "toString" method would be standardized for all Titanium components, "[object TiComponentName]" seems OK choice to me.

Comments

  1. Matthew Apperson 2011-10-13

    Same results in SDK 1.7.2
  2. Ivan Skugor 2011-12-20

    This seems to be fixed in 1.8.0.1 SDK, I haven't verified on iOS, but "v8" got this right, also "JSON.stringify" now works as it should.
  3. Paul Dowsett 2011-12-21

    Reporter has indicated that this is fixed. Just needs to be tested on both platforms.
  4. Karl Åström 2012-01-20

    Actually now toString returns [object View] on v8 and [object TiUIView] on ios so it's not consistent. I would express a preference for the iOS version since it makes it possible to construct a general matcher for Ti-components as noted above. If i could make a really bold request I'd like for titanium to implement its components so that Object.prototype.toString returns good values on iOS as specified in ecma-262 5th ed section 15.2.4.2 Currently it returns [object Object] for all Ti-components on iOS which is less useful.
  5. Ivan Skugor 2012-01-23

    Yeah Karl, you're right, I missed to notice that and I agree "[object TiUIView]" is good naming convention.
  6. Karl Åström 2012-02-07

    Also, as i found out while hunting a particularly annoying bug today, if you have an id property in your view you get neither of these but instead something based on the id like so: Ti.UI.createView({id:'fooBar'}).toString() == '[object fooBar]'
  7. Josh Roesslein 2013-02-01

    We may want to discuss if overriding toString() is a good practice. It may be better to introduce a property on proxies for getting the type name. Ex: var view = Ti.UI.createView(); view.name === 'Ti.UI.View';
  8. Bryan Hughes 2013-02-01

  9. Rene Pot 2020-02-14

    we have apiName property for this.

JSON Source