firebug console API

[align=center] Firebug使用——console API介绍[/align]
原文地址:http://getfirebug.com/console.html
[color=blue] 注:我的英文很烂,这里的翻译也是为了方便自己观看的,英文好的人还是直接看原文吧。[/color]

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.
[color=blue] Firebug在所有的firefox浏览器加载时,增加了一个叫“console”的全局变量,这个对象变量包括很多方法可以让你在FireBug的控制台里查看你的脚本。[/color]

1.console.log(object[, object, ...])
[color=blue]这个方法用于最简单的打LOG,方法类似于JAVA里的System.out.print
javascript里面只有4种类型:
%s 字符串
%d, %i 数字
%f 浮点型
%o 对象
对象类型的变量表现为一个连接,在连接里详细显示对象中的所有属性。[/color]

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

以下红色的文字描述的类似于,log4j的log分级记录:

[color=red]
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.[/color]

console.dir(object)
这个方法是用来展现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.

这个方法是用来展现XML中的所有属性的
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.groupCollapsed(object[, object, ...])
Like console.group(), but the block is initially collapsed.
console.groupEnd()
Closes the most recently opened block created by a call to console.group() or console.groupEnd()

设置时间监控器
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.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值