Created
September 16, 2012 18:04
-
-
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/)
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
/** | |
* 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; | |
}; |
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
// 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