Created
October 17, 2012 17:24
-
-
Save aseabridge/3906865 to your computer and use it in GitHub Desktop.
Javascript object inspector
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
function simpleObjInspect(oObj, key, tabLvl) | |
{ | |
key = key || ""; | |
tabLvl = tabLvl || 1; | |
var tabs = ""; | |
for(var i = 1; i < tabLvl; i++){ | |
tabs += "\t"; | |
} | |
var keyTypeStr = " (" + typeof key + ")"; | |
if (tabLvl == 1) { | |
keyTypeStr = "(self)"; | |
} | |
var s = tabs + key + keyTypeStr + " : "; | |
if (typeof oObj == "object" && oObj !== null) { | |
s += typeof oObj + "\n"; | |
for (var k in oObj) { | |
if (oObj.hasOwnProperty(k)) { | |
s += simpleObjInspect(oObj[k], k, tabLvl + 1); | |
} | |
} | |
} else { | |
s += "" + oObj + " (" + typeof oObj + ") \n"; | |
} | |
return s; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment