Change depth to count down correctly. Trim long lines.

This commit is contained in:
Joel Martin 2010-04-10 12:00:35 -04:00
parent 48617e27bc
commit 4b835baeb9
1 changed files with 9 additions and 4 deletions

View File

@ -6,16 +6,21 @@ function debug(str) {
function dirObj(obj, parent, depth) {
var msg = "";
if (! depth) { depth=0; }
var val = "";
if (! depth) { depth=2; }
if (! parent) { parent= ""; }
// Print the properties of the passed-in object
for (var i in obj) {
if ((depth < 2) && (typeof obj[i] == "object")) {
if ((depth > 1) && (typeof obj[i] == "object")) {
// Recurse attributes that are objects
msg += dirObj(obj[i], parent + "." + i, depth+1);
msg += dirObj(obj[i], parent + "." + i, depth-1);
} else {
msg += parent + "." + i + ": " + obj[i] + "\n";
val = new String(obj[i]).replace("\n", " ");
if (val.length > 30) {
val = val.substr(0,30) + "...";
}
msg += parent + "." + i + ": " + val + "\n";
}
}
return msg;