Skip to content

Instantly share code, notes, and snippets.

@timoa
Created September 16, 2012 18:04
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save timoa/3733523 to your computer and use it in GitHub Desktop.
Save timoa/3733523 to your computer and use it in GitHub Desktop.
Similar "var_dump()" PHP function with Appcelerator Titanium Mobile (http://timoa.com/en/2012/07/appcelerator-dump-javascript-object-ti-api-debug/)
/**
* Debug : var_dump
*
* @var: Var
* @level: Level max
*
*/
function var_dump(_var, _level) {
var dumped_text = "";
if(!_level) _level = 0;
//The padding given at the beginning of the line.
var level_padding = "";
for(var j=0; j<_level+1; j++) level_padding += " ";
if(typeof(_var) == 'object') { //Array/Hashes/Objects
for(var item in _var) {
var value = _var[item];
if(typeof(value) == 'object') { // If it is an array,
dumped_text += level_padding + "'" + item + "' ...\n";
dumped_text += var_dump(value, _level+1);
} else {
dumped_text += level_padding +"'"+ item +"' => \""+ value +"\"\n";
}
}
} else { //Stings/Chars/Numbers etc.
dumped_text = "===>"+ _var +"<===("+ typeof(_var) +")";
}
return dumped_text;
};
// Create a view
var view = Ti.UI.createView({
width: 320,
height: 480,
backgroundColor: '#333333'
});
Ti.API.debug('{---APP---] View:\n' + var_dump(view));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment