In the past, javascript was weak in IO support, so it could not be written into the corresponding text file, and the Error of the exception object was not uniform, so the detailed stack could not be printed. The custom exception object is a very unpleasant method, because we usually only see its message attribute. in addition, other custom attributes need to be traversed cyclically using the slowest for... in. There is no way at this moment. We only need to turn to various private implementations of the browser, such as firefox with console. log. The following is a list of methods for the console object. For more detailed use of firebug, see this article.
Function |
Description |
Log (obj [, obj,...]) |
Output A message to the console. You can enter multiple parameters, and the output will be separated by spaces. The first parameter can contain formatted text, for example: Log ('here % d % s', count, apple ); String format: % S: string. % D, % I: Number. % F: floating point number. % O-hyperlink object.
|
Debug (obj [, obj,...]) |
Output A message to the console, which contains a hyperlink link to the output location. |
Info (obj [, obj,...]) |
Output a message with an information icon and background color to the console. The information contains a hyperlink to the output position. |
Warn (obj [, obj,...]) |
Output a message with a warning icon and background color to the console, which contains a hyperlink to the output location. |
Error (obj [, obj,...]) |
Output a message with an error icon and background color to the console, which contains a hyperlink to the output location. |
Assert (expression [, obj,...]) |
Test whether the value is true. If the value is false, submit an exception to the console. |
Dir (obj) |
Lists all attributes of an object. |
Dirxml (node) |
Lists the XML source trees of HTML or XML elements. |
Trace () |
The call entry of the output stack. |
Group (obj [, obj,...]) |
Output The Information Group to the console. Terminate a group by using groupEnd. |
GroupEnd () |
End Group output. |
Time (name) |
Create a timer named name, calculate the code execution time, call timeEnd (name) to stop the timer, and output the execution time. |
TimeEnd (name) |
Stop the timer named name and output the execution time. |
Profile ([title]) |
Start to test the performance of the script. The title is the test title. |
ProfileEnd () |
End the performance test. |
Count ([title]) |
Calculates the number of times the code is executed. Titile is used as the output title. |
Firebug is not much said, IE8 also has console. log, but this requires pressing F12 to enter the debugging mode. Otherwise, an error is reported. To avoid errors, we should implement an empty object to overwrite it.
Copy codeThe Code is as follows:
If (! Window. console ){
Window. console = {};
Var methods = ["log", "debug", "info", "warn", "error", "assert", "dir", "dirxml ",
"Group", "groupEnd", "time", "timeEnd", "count", "trace", "profile", "profileEnd"],
Noop = function (){}
For (var I = 0, method; method = methods [I ++];)
Window. console [method] = noop;
}
After opera9.5x, there is a new one called Dragonfly. Obviously, it cannot compare with the log output with a wide variety of firebug patterns. It only provides a opera. postError method.
Copy codeThe Code is as follows:
If (window. opera & opera. postError ){
Opera. postError (message );
}
Safari also has console. log, which is based on its Web Inspector component. It feels similar to firefox, but I am not a fruit party and do not know whether there are so many firebugs in its method ...... For the new chrome browser, we can now search for the chrome version installed with firebug in its extension.