Home > Web Front-end > JS Tutorial > Introduction to the console.dir() function in JavaScript_javascript skills

Introduction to the console.dir() function in JavaScript_javascript skills

WBOY
Release: 2016-05-16 16:23:38
Original
1382 people have browsed it

When debugging a JavaScript program, sometimes you need to dump the details of certain objects. This work can be accomplished by manually writing JavaScript code: looping over the properties of the object and printing out each property value looped through; it can be seen that this process is relatively cumbersome. On browsers with debugging tools, this work can be easily accomplished through the console.dir() statement.

Usage of console.dir()

The use of console.dir() is very simple, just pass the object that needs to be dumped directly into this statement. For example:

Copy code 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 newly created cat object information is dumped. The result displayed in the Firebug console is:

If what needs to be dumped is a DOM object, then using console.dirxml() will get a better display effect.

Browser support

console.dir() and console.dirxml() are better supported on browsers with debugging tools, and all major browsers support this function.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template