Skip to content

Instantly share code, notes, and snippets.

@sfate
Created June 8, 2011 22:28
Show Gist options
  • Save sfate/1015596 to your computer and use it in GitHub Desktop.
Save sfate/1015596 to your computer and use it in GitHub Desktop.
simple function that allow to inspect js objects =)
/**
* Inspect object in console.log as simple text
* instead of expandable object structure
*
* Usage(e.g.):
* inspectObj(screen);
*
**/
function inspectObj(obj, indentLength) {
indentLength = fixCount(indentLength);
for(var i in obj){
if ( isObject(obj[i]) ) {
console.log(tabs(indentLength)+i+":");
inspectObj(obj[i], indentLength+1);
}else{
console.log(tabs(indentLength)+i+": "+obj[i]);
}
}
}
function tabs(count){
count = fixCount(count);
var nbsp2 = " ";
var resultTab = nbsp2;
if (count > 1) {
for (i=2;i<=count;i++){
resultTab += nbsp2;
}
}
return resultTab+"[*]";
}
function isObject(object){
return typeof(object) == "object";
}
function fixCount(counter){
return (isNaN(counter) || counter*1 < 1) ? 1 : counter;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment