Previous JavaScript support for IO was weak and could not be written to the corresponding text file, and the exception object error was not uniform and could not print the detailed stack. Customizing the exception object is a very flattering method because we usually only see its message property, and other custom attributes need to be traversed with the slowest for...in loop. At this time there is no way, we have recourse to the browser's various private implementations, such as Firefox has Console.log. The following is a list of methods for the console object, with a more detailed use of the firebug visible in 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 a space separating the parameters output. The first parameter can contain formatted text, for example: Log (' Here is%d%s ', count,apple); String format: %s: String. %d,%i: number. %f: Floating point numbers. %o-Hyperlink object.
|
| Debug (obj[, obj, ...]) |
Output a message to the console that contains a hyperlink linked to the output location. |
| info (obj[, obj, ...]) |
Output a message with an information icon and background color to the console that contains a hyperlink linked to the output location. |
| Warn (obj[, obj, ...]) |
Output a message with a warning icon and background color to the console that contains a hyperlink to the output location. |
| Error (obj[, obj, ...]) |
Output a message with an error icon and background color to the console that contains a hyperlink to the output location. |
| Assert (expression[, obj, ...]) |
Tests whether a representation is true and, if False, submits an exception to the console. |
| Dir (obj) |
Lists all the properties of the object. |
| Dirxml (node) |
An XML source tree that lists HTML or XML element. |
| Trace () |
The call entry for the output stack. |
| Group (obj[, obj, ...]) |
The information is grouped and then exported to the console. Ends the grouping by GroupEnd (). |
| GroupEnd () |
Ends the grouping output. |
| Time (name) |
Create a timer named name, calculate the execution time of the code, call Timeend (name) to stop the timer, and output the execution time. |
| Timeend (name) |
Stops the timer named name and outputs the execution time. |
| Profile ([title]) |
Start the performance test of the script, title is the test title. |
| Profileend () |
End the performance test. |
| Count ([title]) |
Count the number of times the code was executed. Titile as the output header. |
Firebug since not much said, IE8 also have console.log, but this need to press F12, into the debug mode only effective, or error. In order not to complain, usually we should implement an empty object to cover it.
Copy Code code 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;
}
Probably opera9.5x after it, a lot of a call Dragonfly Dongdong. Obviously, it does not compare with the firebug of a variety of log output, it only provides a Opera.posterror method.
Copy Code code as follows:
if (Window.opera && opera.posterror) {
Opera.posterror (message);
}
Safari also has Console.log, it is based on its web inspector components, feel similar to Firefox, but I am not a fruit party, do not know its method is not firebug so much ... For browsers upstart Chrome, now we can search its extender to install Firebug's Chrome version.