This article mainly introduces the console in JavaScript. dir () function introduction, console. dir is mainly used to dump the detailed information of some objects. For more information, see dump the detailed information of some objects when debugging JavaScript programs. By writing JavaScript code manually, you can do this: loop the attributes of an object and print out each attribute value that is returned by the Loop. Obviously, this process is cumbersome. In browsers with debugging tools, this work can be easily completed through the console. dir () statement.
Use of console. dir ()
The use of console. dir () is very simple. you just need to pass the dump object to this statement. For example:
The code 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 new cat object information is dumped. In the Firebug console, the result is:
If you need to dump a DOM object, you can use console. dirxml () to better display the object.
Browser support
Console. dir () and console. dirxml () are well supported in browsers with debugging tools. all major browsers support this function.