Created
July 27, 2012 07:22
-
-
Save jpalala/3186633 to your computer and use it in GitHub Desktop.
javascript dumping contents of a javascript variable or object file
This file contains hidden or 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
var MAX_DUMP_DEPTH = 10; | |
function dumpObj(obj, name, indent, depth) { | |
if (depth > MAX_DUMP_DEPTH) { | |
return indent + name + ": <Maximum Depth Reached>\n"; | |
} | |
if (typeof obj == "object") { | |
var child = null; | |
var output = indent + name + "\n"; | |
indent += "\t"; | |
for (var item in obj) | |
{ | |
try { | |
child = obj[item]; | |
} catch (e) { | |
child = "<Unable to Evaluate>"; | |
} | |
if (typeof child == "object") { | |
output += dumpObj(child, item, indent, depth + 1); | |
} else { | |
output += indent + item + ": " + child + "\n"; | |
} | |
} | |
return output; | |
} else { | |
return obj; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment