Hi, my name is Timo Ernst and I am a web expert.

Object inspector for JavaScript

Posted on: December 21st, 2009 by Timo

Sometimes, one cannot inspect JavaScript-objects using an external debugger, like Firebug.

For example, this can happen during development of Firefox addons: Open the JavaScript inspector of Firebug and you will only see the JavaScript errors on the currently displayed website, but not the ones from the addon.

Thus, I modified the inspect()-function from Ariel Tapia (codeprojects.com) a bit. My version will not only return a HTML string with all the attributes and functions that are inside the object. It will also add the values of these.

Installation: Just unzip the file and include it via
<script src="inspector.js" type="text/javascript"></script>
(As an alternative, you can also just copy and paste the function directly into your source.)

Example usage: var htmlResult = inspect(myObject, null, null);
htmlResult will now hold a string-representation of the properties and functions of myObject.

Note: An alternative for Firefox addons is Venkman. Haven’t really figured out how to use that though.
So, if you don’t want to bother with Venkman or need an object-inspector for any other purpose, I think you’ll be fine with my function provided above.

TwitterDiggFacebookShare

Tags: , , , ,

One Response

  1. bernie says:

    Thank you,

    I’ve written a simpler function:

    function objInsp(obj) {
    var html = ‘<ul>’;
    for (var i in obj) {
    html += ‘<li>’ + i + ‘ : ‘ + ((‘object’ == typeof obj[i]) ? objInsp(obj[i]) : obj[i]) + ‘</li>’;
    }
    html += ‘</ul>’;
    return html;

    Thumb up 2 Thumb down 0

Leave a Reply