Debugging JavaScript: object dump

From time to time you want a dump of an object during execution of code. This function provides missing functional.

function odump(object, depth, max){
    depth = depth || 0;
    max = max || 2;
    if (depth > max)
        return false;
    var indent = "";
    for (var i = 0; i < depth; i++)
        indent += " ";
    var output = "";
    for (var key in object){
        output += "n" + indent + key + ": ";
        switch (typeof object[key]){
            case "object": output += odump(object[key], depth + 1, max); break;
            case "function": output += "function"; break;
            default: output += object[key]; break;
        }
    }
    return output;
}

 

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Related Post

%d bloggers like this: