Home > Web Front-end > JS Tutorial > body text

javascript debugging instructions_javascript skills

WBOY
Release: 2016-05-16 18:25:34
Original
827 people have browsed it

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(obj[, obj, ...]) 向控制台输出一个信息。可以输入多个参数,输出将已空格分隔各参数输出。
第一参数可以包含格式化文本,例如:
log(‘这里有%d个%s',count,apple);
字符串格式:
%s:字符串。
%d, %i:数字。
%f: 浮点数。
%o -超链接对象。
debug(obj[, obj, ...]) 向控制台输出一个信息,信息包含一个超链接链接到输出位置。
info(obj[, obj, ...]) 向控制台输出一个带信息图标和背景颜色的信息,信息包含一个超链接链接到输出位置。
warn(obj[, obj, ...]) 向控制台输出一个带警告图标和背景颜色的信息,信息包含一个超链接链接到输出位置。
error(obj[, obj, ...]) 向控制台输出一个带错误图标和背景颜色的信息,信息包含一个超链接链接到输出位置。
assert(expression[, obj, ...]) 测试一个表示是否为true,如果为false,提交一个例外信息到控制台。
dir(obj) 列出对象的所有属性。
dirxml(node) 列出HTML或XML Element的XML源树。
trace() 输出堆栈的调用入口。
group(obj[, obj, ...]) 将信息分组再输出到控制台。通过groupEnd()结束分组。
groupEnd() 结束分组输出。
time(name) 创建一个名称为name的计时器,计算代码的执行时间,调用timeEnd(name)停止计时器并输出执行时间。
timeEnd(name) 停止名称为name的计时器并输出执行时间。
profile([title]) 开始对脚本进行性能测试,title为测试标题。
profileEnd() 结束性能测试。
count([title]) 计算代码的执行次数。titile作为输出标题。
The first parameter can contain formatted text, for example:
log(‘There are %d %s’, count, apple);
String format:
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.
I won’t go into detail about firebug. IE8 also has console.log, but this only takes effect when you press F12 and enter debugging mode, otherwise an error will be reported. In order not to report an error, we should usually 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; } Probably after opera9.5x, there is an additional thing called Dragonfly East. Obviously, it cannot be compared with the various log output of firebug. It only provides an opera.postError method.


Copy code

The code is as follows:
if (window.opera && opera.postError) { opera.postError(message); } Safari also has a console.log, which is based on its Web Inspector component and feels similar to firefox, but I am not a fruit person and don’t know about it. There are not as many methods as firebug... For the upstart browser chrome, we can now search for the chrome version where firebug is installed in its extension.
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template