Skip to content

Instantly share code, notes, and snippets.

@dasher
Created July 6, 2010 11:07
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save dasher/465256 to your computer and use it in GitHub Desktop.
Save dasher/465256 to your computer and use it in GitHub Desktop.
// 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;
}
}
}
}
@gvt
Copy link

gvt commented Apr 18, 2011

this code seems useful. when I use it on a TiUIWindow object, the iPhone app crashes in the simulator when I use goDeep=true

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment