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 seek help from various private implementations of the browser, such as console. Log in Firefox. The following is a list of methods of 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 and calculateCodeCall 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 code The 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 code The Code is as follows: if (window. Opera & opera. posterror ){
Opera. posterror (Message );
}
Safari
There is also console. log, which is based on its Web
The Inspector component is similar to Firefox, but I am not a fruit party. I don't know if there are so many firebugs in the method ...... For chrome, now I
You can expandProgramSearch for the chrome version for firebug installation.