Object inspector (Useful tip)

A debugging tool for inspecting object properties and classes.

Here is a small debugging utility that breaks an object down and displays some of its properties.

Example code:

   <!-- An example for use on Netscape only -->
   <HTML>
   <HEAD>
   <SCRIPT>
   function object_dump(anObject)
   {
      document.write("<HR>");
      document.write("<TABLE BORDER=1>");
      table_row("<B>Item</B>", "<B>Value</B>");
   
      if(typeof anObject != "object")
      {
         table_row("Value", anObject);
         table_row("Typeof", typeof(anObject));
      }
      else
      {
         table_row("Value", anObject.valueOf());
         table_row("String equiv", anObject.toString());
         table_row("Typeof", typeof(anObject));
         table_row("Class", anObject.constructor.name);
         table_row("Prototype", anObject.prototype);
      }
   
      document.write("</TABLE>");
      document.write("<HR>");
   }
   
   function table_row(anItem, aName)
   {
      document.write("<TR>");
      document.write("<TD>");
      document.write(anItem);
      document.write("</TD>");
      document.write("<TD>");
      document.write(aName);
      document.write("</TD>");
      document.write("</TR>");
   }
   </SCRIPT>
   </HEAD>
   <BODY>
   <SCRIPT>
   function nest(abc)
   {
      test("aa", bb, 100);
   }
   function test(aa, bb, cc, dd)
   {
      object_dump(aa);
      object_dump(bb);
      object_dump(cc);
      object_dump(arguments.caller.callee.name);
      object_dump(arguments.callee.constructor.name);
   }
   var bb;
   nest("aa", bb, 100);
   object_dump(document);
   </SCRIPT>
   </BODY>
   </HTML>

See also:Arguments object, Debugging - client-side, typeof