Created
June 8, 2011 22:28
-
-
Save sfate/1015596 to your computer and use it in GitHub Desktop.
simple function that allow to inspect js objects =)
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
/** | |
* 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