FireBug 是一个非常实用的JavaScript以及DOM查看调试工具,是 Firefox 的一个插件。使用 FireBug 调试 AJAX 应用非常方便,终于可以告别 alert 时代了!
Console Logging 函数
FireBug 为所有 Web 页面提供了一个 console 对象。这个对象有以下函数:
Logging 基础
Logging 等级
通常根据不同的等级来区分Logging的严重程度是很有帮助的。FireBug 提供了4个等级。为了达到视觉分离的效果,这些函数与 log 不同的地方就是它们在被调用的时候会自动包含一个指向代码行数的链接。
断言
断言是一条确保代码规则的非常好的途径。console 对象包含了一系列各种类型的断言函数,并且允许你编写自己的断言函数。
a is true.
a is equal to
b.
a is not equal to
b.
a is greater than
b.
a is not greater than
b.
a is less than
b.
a is not less than
b.
a is in the array
b.
a is not in the array
b.
a is equal to
true.
a is equal to
false.
a is equal to
null.
a is not equal to
null.
a is equal to
undefined.
a is not equal to
undefined.
a is an instance of type
b.
a is not an instance of type
b.
a is equal to the string
b.
a is not equal to the string
b.
测量(Measurement)
下面的一些函数可以让你方便的测量你的一些代码。
字符串格式化
所有 console 的 logging 函数都可以通过以下模式格式化字符串:
如果你需要一个真实的 % 符号,你可以通过一个转移符号就像这样 "/%"。
命令行函数
内建的命令行函数可以通过以下命令行使用:
4 Responses to “FireBug 控制台函数说明”
---------------------------------------------------------------------Firebug adds a global variable named "console" to all web pages loaded in Firefox. This object contains many methods that allow you to write to the Firebug console to expose information that is flowing through your scripts.
console.log(object[, object, ...])
Writes a message to the console. You may pass as many arguments as you'd like, and they will be joined together in a space-delimited line.
The first argument to log may be a string containing printf-like string substitution patterns. For example:
console.log("The %s jumped over %d tall buildings", animal, count);
The example above can be re-written without string substitution to achieve the same result:
console.log("The", animal, "jumped over", count, "tall buildings");
These two techniques can be combined. If you use string substitution but provide more arguments than there are substitution patterns, the remaining arguments will be appended in a space-delimited line, like so:
console.log("I am %s and I have:", myName, thing1, thing2, thing3);
If objects are logged, they will be written not as static text, but as interactive hyperlinks that can be clicked to inspect the object in Firebug's HTML, CSS, Script, or DOM tabs. You may also use the %o pattern to substitute a hyperlink in a string.
Here is the complete set of patterns that you may use for string substitution:
| String Substitution Patterns | |
| %s | String |
| %d, %i | Integer (numeric formatting is not yet supported) |
| %f | Floating point number (numeric formatting is not yet supported) |
| %o | Object hyperlink |
console.debug(object[, object, ...])
Writes a message to the console, including a hyperlink to the line where it was called.
console.info(object[, object, ...])
Writes a message to the console with the visual "info" icon and color coding and a hyperlink to the line where it was called.
console.warn(object[, object, ...])
Writes a message to the console with the visual "warning" icon and color coding and a hyperlink to the line where it was called.
console.error(object[, object, ...])
Writes a message to the console with the visual "error" icon and color coding and a hyperlink to the line where it was called.
console.assert(expression[, object, ...])
Tests that an expression is true. If not, it will write a message to the console and throw an exception.
console.dir(object)
Prints an interactive listing of all properties of the object. This looks identical to the view that you would see in the DOM tab.
console.dirxml(node)
Prints the XML source tree of an HTML or XML element. This looks identical to the view that you would see in the HTML tab. You can click on any node to inspect it in the HTML tab.
console.trace()
Prints an interactive stack trace of JavaScript execution at the point where it is called.
The stack trace details the functions on the stack, as well as the values that were passed as arguments to each function. You can click each function to take you to its source in the Script tab, and click each argument value to inspect it in the DOM or HTML tabs.
console.group(object[, object, ...])
Writes a message to the console and opens a nested block to indent all future messages sent to the console. Call console.groupEnd() to close the block.
console.groupEnd()
Closes the most recently opened block created by a call to console.group.
console.time(name)
Creates a new timer under the given name. Call console.timeEnd(name) with the same name to stop the timer and print the time elapsed..
console.timeEnd(name)
Stops a timer created by a call to console.time(name) and writes the time elapsed.
console.profile([title])
Turns on the JavaScript profiler. The optional argument title would contain the text to be printed in the header of the profile report.
console.profileEnd()
Turns off the JavaScript profiler and prints its report.
console.count([title])
Writes the number of times that the line of code where count was called was executed. The optional argument title will print a message in addition to the number of the count.
224

被折叠的 条评论
为什么被折叠?



