Introduction to the console. dir () function in JavaScript _ javascript skills

Source: Internet
Author: User
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.

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.