When debugging a JavaScript program, you sometimes need to dump some of the object's details. This work can be done by writing JavaScript code by hand: Looping through the properties of the object, printing each property value that is looping to it, and this process is quite tedious. In browsers with debugging tools, this work can be done conveniently through the console.dir () statement.
Use of Console.dir ()
The use of Console.dir () is very simple, and the object that needs to dump is passed in directly to the statement. For example, the following examples:
Copy Code code as follows:
function Cat (name, age, score) {
THIS.name = name;
This.age = age;
This.score = score;
}
var C = new Cat ("Miao", 2, [6,8,7]);
Console.dir (c);
By using Console.dir (), the new Cat object information is dump out. The results displayed in the Firebug console are:
If you need to dump a DOM object, then using Console.dirxml () will get a better display.
Browser support
Console.dir () and Console.dirxml () are well supported in browsers with debugging tools, and are supported by major browsers.