Created
June 4, 2012 12:13
-
-
Save iskugor/2867975 to your computer and use it in GitHub Desktop.
Titanium WTF: Window children property
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var win = Ti.UI.createWindow({ backgroundColor: "#fff", navBarHidden: true, layout: 'horizontal' }); | |
var view = Ti.UI.createView({ | |
layout: 'horizontal' | |
}); | |
var label1 = Ti.UI.createLabel({ | |
top: 150, | |
left: 50, | |
text: 'Testing 1 ...', | |
height: '75dp', | |
width: '50%', | |
backgroundColor: "#000" | |
}); | |
var textField = Ti.UI.createTextField({ | |
top: 150, | |
left: 50, | |
width: '150dp', | |
height: '75dp', | |
}); | |
var label2 = Ti.UI.createLabel({ | |
top: 150, | |
left: 50, | |
text: 'Testing 2 ...', | |
height: '75dp', | |
width: '50%', | |
backgroundColor: "#000" | |
}); | |
var picker = Ti.UI.createPicker({ | |
top: 150, | |
left: 50, | |
height: '75dp', | |
backgroundColor: "#999", | |
selectionIndicator : true | |
}); | |
var data = []; | |
data[0] = Ti.UI.createPickerRow({ title:'Bananas' }); | |
data[1] = Ti.UI.createPickerRow({ title:'Strawberries' }); | |
data[2] = Ti.UI.createPickerRow({ title:'Mangos' }); | |
data[3] = Ti.UI.createPickerRow({ title:'Grapes' }); | |
picker.add(data); | |
view.add(label1); | |
view.add(textField); | |
view.add(label2); | |
view.add(picker); | |
win.add(view); | |
win.addEventListener('open', function() { | |
Ti.API.info('View'); | |
Ti.API.info(typeof view.children); // "object" - should be "[object Array]" | |
Ti.API.info(typeof view._children); // "undefined" - OK | |
Ti.API.info(view.children.length); // "4" - OK | |
Ti.API.info('Window'); | |
Ti.API.info(typeof win.children); // "object" - should be "[object Array]" | |
Ti.API.info(typeof win._children); // "object" - should be "undefined" | |
Ti.API.info(win.children.length); // "0" - should be "1" | |
Ti.API.info(win._children.length); // "1" - should throw an exception since "_children" should be undefined | |
}); | |
win.open(); |
Yeah, you're right, mea culpa. I used "typeof" and thinking about "Object.prototype.toString.call(foo)". :)
I should have specified, this was an Android test. :D
On iOS, there is no "_children" property, that property exists on Android only and it seems it does what "children" should (and "children" does nothing).
Ah, no worries, I was going through your public gists and came across this one. :) Thats all.
The _children
you are talking about, could be some private Titanium API, I mean, internal that somehow found its way to the JS.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Everything in JS are objects.
Open the web browser inspector and try this:
The typeof return an "object"
:)
So I tested this code, and
win._children.length
throws an error: