Created
July 6, 2010 11:07
-
-
Save dasher/465256 to your computer and use it in GitHub Desktop.
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
// Simple debug output helper | |
function debug(message) { | |
Ti.API.info(message); | |
} | |
/** | |
* | |
* @param thisControl The control you wish to dump | |
* @param goDeep boolean Do you want deep introspection | |
* @param incFuncs boolean Do you want to include functions in the output when going deep | |
* @return null | |
*/ | |
function dumpObj2(thisControl, goDeep, incFuncs) { | |
// Some sanity checks | |
if (thisControl == null) { | |
debug("Can't do much with null"); | |
return; | |
} | |
// Start simple | |
var objectName = typeof thisControl; | |
debug("["+objectName+"] thinks it's a "+thisControl.toString()); | |
debug("The constructor of ["+objectName+"] thinks it's a/an "+typeof thisControl.constructor) | |
try { | |
debug("Dynamic Properties: "+JSON.stringify(thisControl.getDynamicProperties())); | |
} catch (e) { | |
debug("No Dynamic Properties"); | |
} | |
if (goDeep) { | |
// thisControl is the item you wish to debug | |
for(p in thisControl) { | |
// Define a default type | |
var typeName = "property"; | |
try { | |
// Grab a handle to allow us to check | |
var typeHandle = thisControl[p]; | |
if (typeof typeHandle == "function") { | |
// We have a function | |
if (!incFuncs) { | |
// Ignore it | |
continue; | |
} | |
typeName = typeHandle; | |
} | |
} catch (e) { | |
// Oops - we have a problem - not an issue | |
//Ti.API.info("Exception with "+p); | |
} | |
// Basic info | |
debug("["+typeName+"] "+p); | |
switch (typeName) { | |
case "property": | |
try { | |
if ("object" == typeof thisControl[p]) { | |
dumpObj2(thisControl[p]); | |
} else { | |
debug("value type: "+ typeof thisControl[p]); | |
debug("Value: "+thisControl[p]); | |
} | |
} catch (e) { | |
// TODO: handle exception | |
} | |
break; | |
case "function": | |
// Nothing | |
break; | |
case "object": | |
// Recursive for objects | |
try { | |
dumpObj2(thisControl[p]) | |
} catch (e) { | |
// Do nothing | |
} | |
break; | |
default: | |
// Nothing | |
break; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
this code seems useful. when I use it on a TiUIWindow object, the iPhone app crashes in the simulator when I use goDeep=true