Console API
When you open firebug (which also includes built-in debugging tools for chrome and other browsers), the window will register an object called console. It provides multiple methods to output information to the console for developers to debug and use. The following is a brief introduction to these methods. using them in a timely manner is helpful for improving development efficiency.
Console. Log (object [, object,...])
The most frequently used statement: outputs a message to the console. Supports C-language printf formatted output. Of course, you can do the same without formatting the output:
var animal=‘frog‘, count=10; console.log("The %s jumped over %d tall buildings", animal, count); console.log("The", animal, "jumped over", count, "tall buildings");
Console. debug (object [, object,...])
Output A message to the console, which contains a hyperlink pointing to the location of the Code in the row.
Console.info (object [, object,...])
Output A message to the console, which contains an icon indicating "information" and a hyperlink pointing to the location of the code for this row.
Console. Warn (object [, object,...])
Same as info. The difference is that the icon and style are different.
Console. Error (object [, object,...])
Same as info. The difference is that the icon and style are different. Error is actually the same as throw new error (). When this statement is used, a JS exception is thrown to the browser.
Console. Assert (expression [, object,...])
To test whether an expression is true. If the expression is not true, an exception (assertion failure) is thrown ).
Console. dir (object)
Outputs all attributes of an object (the output result is similar to the style in the DOM panel ).
Console. dirxml (node)
Output The Structure Tree of an HTML or XML element. Click the node on the structure tree to enter the HTML panel.
Console. Trace ()
Outputs the stack trace for javascript execution.
Console. Group (object [, object,...])
When a message is output, a nested block is opened to indent the output content. Call console. groupend () to end the output of this block.
Console. groupcollapsed ()
Compared with console. Group ();, nested blocks are collapsed by default.
Console. Time (name)
Timer. When console. timeend (name) is called and the same name is passed as the parameter, the timer is stopped and the time consumed by the code between the two statements is output (in milliseconds ).
Console. Profile ([title])
It is used in combination with profileend () for performance testing. It has the same functions as the Profile button on the console panel.
Console. Count ([title])
The number of times the code of the row is executed. The title parameter is used as the prefix of the output result.
Console. Clear ()
Clear Console
Command Line
The right side of the output panel of the console is the Input Panel of the console (the chrome debugging tool corresponds to the bottom). In addition to running common JavaScript code, A considerable number of command lines are built in to help with debugging. Below is a brief introduction to some common command lines.
$ (ID)
Returns the element of a given ID.
$ (Selector)
Returns a group of elements matched by the given CSS selector.
$ X (XPath)
Returns a group of elements that match the given XPath expression.
$0
Select an element from the HTML panel.
$1
The last element selected in the HTML panel.
$ N (INDEX)
Access the last five selected elements. The index range is 0-4.
Dir (object)
Same as console. dir (object ).
Dirxml (node)
Same as console. dirxml (node ).
Clear ()
Same as console. Clear ().
Inspect (object [, tabname]) ()
View an object in the appropriate (or a specified) tab.
Keys (object)
Returns the keys of all attributes of an object.
Values (object)
Returns the values of all attributes of an object.
Debug (FN)
Add a breakpoint in the first line of the function and use undebug (FN) to remove the breakpoint.
Monitor (FN)
Enable the call log of a function and disable this function using unmonitor (FN. A very useful command, but it does not seem to work well.
Monitorevents (object [, Types])
Log records when an event (or all events) of an element is triggered. Use Cases:
monitorEvents($0,[‘click‘])
After the preceding command line is executed, click event monitoring is enabled for the selected element in the HTML panel. Once the click event of this element is triggered, the event object will be output on the console. If the second parameter is not specified, all events are recorded.
Profile ([title])
Same as console. Profile ([title])
Address: http://visionsky.blog.51cto.com/733317/543789
Firebug & chrome console user guide