Firebug console details

Source: Internet
Author: User


The console is the first and most important panel of firebug. It is mainly used to display various types of information generated during webpage loading.

1. Command for displaying information

Firebug has a built-in console object, which provides five methods for displaying information.

The simplest method is console. Log (), which can be used to replace alert () or document. Write (). For example, if you use console. Log ("Hello World") in a web script, the console automatically displays the following content during loading.

In addition, according to the different nature of information, there are four methods for displaying information in the console object, namely the general information lele.info () and the debugging information console. debug (), warning console. warn (), error prompt console. error ().

For example, insert the following four lines in a web script:

Console.info ("this is Info ");

Console. debug ("this is debug ");

Console. Warn ("this is warn ");

Console. Error ("this is error ");

When loading, the console displays the following content.

You can see that there are different icons in front of different types of information, and each piece of information is followed by a hyperlink. Click it and jump to the corresponding line of the web page source code.

2. placeholders

Any of the above five methods of the console object can use a printf-style placeholder. However, there are few placeholders. Only characters (% s), integers (% d or % I), floating point numbers (% F), and objects (% O) are supported.

For example,

Console. Log ("% d", 2011,3, 26 );

Console. Log ("the circumference rate is % F", 3.1415926 );

% O placeholder, which can be used to view the internal situation of an object. For example, there is such an object:

VaR dog = {};

Dog. Name = "Mao ";

Dog. color = "yellow ";

Then, use the o % placeholder for it.

Console. Log ("% O", dog );

3. group display

If there is too much information, it can be displayed in groups. The methods used are console. Group () and console. groupend ().

Console. Group ("group 1 information ");

Console. Log ("first group 1 ");

Console. Log ("the first group and the second group ");

Console. groupend ();

Console. Group ("group 2 information ");

Console. Log ("second group first ");

Console. Log ("second entry in the second group ");

Console. groupend ();

Click the group title. The group information is folded or expanded.

Iv. Console. dir ()

Console. dir () can display all attributes and methods of an object.

For example, add a bark () method for the dog object in section 2.

Dog. Bark = function () {alert ("Wang Wangwang ");};

Then, the content of the object is displayed,

Console. dir (DOG );

V. Console. dirxml ()

Console. dirxml () is used to display the HTML/XML Code contained by a node on a webpage.

For example, first obtain a table node,

VaR table = Document. getelementbyid ("Table1 ");

The Code contained in the node is displayed.

Console. dirxml (table );

6. Console. Assert ()

Console. Assert () is used to determine whether an expression or variable is true. If the result is no, a message is output on the console and an exception is thrown.

For example, the following two results are no.

VaR result = 0;

Console. Assert (result );

VaR year = 2000;

Console. Assert (year = 2011 );

7. Console. Trace ()

Console. Trace () is used to track the call track of a function.

For example, there is a multiplier function.

Function add (a, B ){

Return A + B;

}

I want to know how this function is called. Just add the console. Trace () method to it.

Function add (a, B ){

Console. Trace ();

Return A + B;

}

Assume that the call code of this function is as follows:

VaR x = add3 (1, 1 );

Function add3 (a, B) {return Add2 (a, B );}

Function Add2 (a, B) {return Add1 (a, B );}

Function Add1 (a, B) {return add (a, B );}

After running, the call track of add () is displayed, from top to bottom: add (), Add1 (), Add2 (), and add3 ().

8. Timing Function

Console. Time () and console. timeend () are used to display the code running time.

Console. Time ("timer 1 ");

For (VAR I = 0; I <1000; I ++ ){

For (var j = 0; j <1000; j ++ ){}

}

Console. timeend ("timer 1 ");

IX. Performance Analysis

Performance analysis (Profiler) is used to analyze the running time of each part of the program and identify the bottleneck. The method used is console. Profile ().

Assume that there is a function Foo (), which calls the other two functions funca () and funcb (), where funca () calls 10 times and funcb () calls once.

Function Foo (){

For (VAR I = 0; I <10; I ++) {funca (1000 );}

Funcb (10000 );

}

Function funca (count ){

For (VAR I = 0; I <count; I ++ ){}

}

Function funcb (count ){

For (VAR I = 0; I <count; I ++ ){}

}

Then, you can analyze the Running Performance of Foo.

Console. Profile ('performance analyzer 1 ');

Foo ();

Console. profileend ();

The console displays a performance analysis table, as shown in.

The title bar prompts that a total of 12 functions were run, which took 2.656 milliseconds. Among them, funca () runs 10 times, taking 1.391 milliseconds, the shortest running time is 0.123 milliseconds, the longest running time is 0.284 milliseconds, and the average running time is 0.139 milliseconds; funcb () runs 1 time, taking Ms milliseconds.

In addition to the console. Profile () method, firebug also provides a "Profile" button. Click this button for the first time to start with "Performance Analysis". You can perform some operations (such as Ajax operations) on the webpage, and then click this button for the second time to end with "Performance Analysis, all operations caused by this operation perform performance analysis.

10. Attribute menu

There is an inverted triangle behind the name of the console panel. After you click it, the attribute menu is displayed.

By default, the console only displays JavaScript errors. If JavaScript warnings, CSS errors, and XML errors are selected, the related prompts are displayed.

What is useful here is "display xmlhttprequests", that is, display Ajax requests. After selection, all Ajax requests on the webpage will be displayed on the console panel.

For example, if you click a Yui example, the console will tell us that it uses ajax to send a GET request, HTTP request and response header information and content body.

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.