In the past, JavaScript's support for IO was very weak and could not be written to the corresponding text file. Moreover, the exception object Error was not uniform and could not print a detailed stack. Customizing an exception object is a very unpleasant method, because usually we only see its message attribute. Furthermore, other custom attributes need to be traversed using the slowest for...in loop. There is no other way at this time. We can only resort to various private implementations of browsers. For example, Firefox has console.log. The following is a list of methods of the console object. For more detailed use of firebug, please see this article.
Function | Description | ||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
log(obj[, obj, ...]) | Outputs a message to the console. You can enter multiple parameters, and the output will be separated by spaces.
log(‘There are %d %s’, count, apple); String format: %s: string. %d, %i: numbers. %f: Floating point number. %o - Hyperlink object.
|
||||||||||||||||||||||||||||||||||
debug(obj[, obj, ...]) | Outputs a message to the console containing a hyperlink to the output location. | ||||||||||||||||||||||||||||||||||
info(obj[, obj, ...]) | Outputs a message to the console with a message icon and background color. The message contains a hyperlink to the output location. | ||||||||||||||||||||||||||||||||||
warn(obj[, obj, ...]) | Outputs a message with a warning icon and background color to the console. The message contains a hyperlink to the output location. | ||||||||||||||||||||||||||||||||||
error(obj[, obj, ...]) | Outputs a message to the console with an error icon and background color. The message contains a hyperlink to the output location. | ||||||||||||||||||||||||||||||||||
assert(expression[, obj, ...]) | Tests whether a representation is true and, if false, submits an exception message to the console. | ||||||||||||||||||||||||||||||||||
dir(obj) | Lists all properties of the object. | ||||||||||||||||||||||||||||||||||
dirxml(node) | Lists the XML source tree of HTML or XML Element. | ||||||||||||||||||||||||||||||||||
trace() | The call entry of the output stack. | ||||||||||||||||||||||||||||||||||
group(obj[, obj, ...]) | Groups information and outputs it to the console. End the group through groupEnd(). | ||||||||||||||||||||||||||||||||||
groupEnd() | End group 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) | Stop the timer named name and output the execution time. | ||||||||||||||||||||||||||||||||||
profile([title]) | Start performance testing of the script, title is the test title. | ||||||||||||||||||||||||||||||||||
profileEnd() | End performance test. | ||||||||||||||||||||||||||||||||||
count([title]) | Counts the number of times the code is executed. title as the output title. |