The Console.dir () function in JavaScript describes _javascript techniques

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.