[TIMOB-5744] Android: Titanium objects' toString method is not consistent
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | Trivial |
Status | Closed |
Resolution | Won't Fix |
Resolution Date | 2020-02-14T09:15:57.000+0000 |
Affected Version/s | Release 1.7.3 |
Fix Version/s | n/a |
Components | Android |
Labels | n/a |
Reporter | Ivan Skugor |
Assignee | Rene Pot |
Created | 2011-10-12T05:04:33.000+0000 |
Updated | 2020-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.
Same results in SDK 1.7.2
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.
Reporter has indicated that this is fixed. Just needs to be tested on both platforms.
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.
Yeah Karl, you're right, I missed to notice that and I agree "[object TiUIView]" is good naming convention.
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]'
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';
we have
apiName
property for this.