When debugging JavaScript programs, you sometimes need to dump the details of certain objects. This work can be accomplished by manually writing JavaScript code: looping for the properties of the object and printing out each property value that is looped to; it can be seen that this process is quite cumbersome. In browsers with debugging tools, this work can be easily accomplished through the console.dir() statement.
Use of console.dir()
The use of console.dir() is very simple, just pass the object that needs dump into this statement. For example, the following example:
The code copy is 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 newly created cat object information is dumped. In the Firebug console, the result is:
If the one that needs to dump is a DOM object, then using console.dirxml() will get a better display effect.
Browser support
console.dir() and console.dirxml() are well supported on browsers with debugging tools, and all major browsers support this function.