定义:Prints an XML representation of the descendant elements of object if possible, or the JavaScript representation if not. Calling console.dirxml() on HTML and XML elements is equivalent to calling console.log().
译文:如果可能,打印对象的后代元素的XML表示,如果不可能,则打印javaScript表示。对于html和xml元素,调用console.dirxml()相当于调用console.log();
示例1:
console.dirxml(obj)
result:
示例2:
console.dir(document);
result:
示例3:
console.log(document);
rersult:
7、console.error(object [, object, ...])
定义:Prints a message similar to console.log(), styles the message like an error, and includes a stack trace from where the method was called.
译文:打印一条类似于console.log()打印的消息,错误样式和包括堆栈跟踪。
示例1:
function logName(obj){ if(obj.name==undefined){ console.error('name is undefined') } } logName({});
result:
示例2:
console.error('print error Information');
result:
8、console.group(object[, object, ...])
定义:Starts a new logging group with an optional title. All console output that occurs after console.group() and before console.groupEnd() is visually grouped together.
译文:开始一个带有可选标题的日志组。所有控制台输出的内容被包含在以console.group()开始和以consol.groupEnd()结束之间。
示例1:
function name(obj) { console.group('name'); console.log('first: ', obj.first); console.log('middle: ', obj.middle); console.log('last: ', obj.last); console.groupEnd(); } name({"first":"Wile","middle":"E","last":"Coyote"});
result:
示例2:
function name(obj) { console.group('name'); console.log('first: ', obj.first); console.log('middle: ', obj.middle); console.log('last: ', obj.last); console.groupEnd(); } function doStuff() { console.group('doStuff()'); name({"first":"Wile","middle":"E","last":"coyote"}); console.groupEnd(); } doStuff();
result:
9、console.groupCollapsed(object[, object, ...])
定义:Creates a new logging group that is initially collapsed instead of open.
译文:创建一个新的初始化倒塌而不是开放的日志组。
示例:
console.groupCollapsed('status'); console.log("peekaboo, you can't see me"); console.groupEnd();
result:
10、console.groupEnd()
定义:Closes a logging group. See console.group for an example.
译文:创建日志组。以console.group()作为例子。
11、console.info(object [, object, ...])
定义:Prints a message like console.log() but also shows an icon (blue circle with white "i") next to the output.
译文:不仅打印一条像console.log()一样的消息,而且也显示了一个紧挨着输出结果的图标(带有"i"的蓝色圈)。
示例:
console.info('带有"i"的蓝色圈')
result:
12、console.log(object [, object, ...])
定义:Displays a message in the console. Pass one or more objects to this method.Each object is evaluated and concatenated into a space-delimited string.
译文:将消息显示在控制台。将一个或多个对象传递给这个方法。每个队对象被计算成和连接成一个空格分隔字符串。
示例:
console.log('Hello, Logs!');
result:
13、console.marktimeline()
已经被弃用,已被console.timeStamp替换。
示例:
console.markTimeline();
result:
14、console.profile([label])
定义:Starts a JavaScript CPU profile with an optional label. To complete the profile, call console.profileEnd(). Each profile is added to the Profiles panel.
译文:开始一个带有可选标签的JavaScript CPU性能分析。以console.profileEnd()作为整个性能分析结束的标记。每次性能分析结果被附加到性能分析面板。
示例:
function processPixels() { console.profile("processPixels()"); // later, after processing pixels console.profileEnd(); } processPixels();
result:
15、console.profileEnd()
定义:Stops the current JavaScript CPU profiling session if one is in progress and prints the report to the Profiles panel.See console.profile() for an example.
译文:如果性能分析进行中和把分析报告打印到性能分析面板,停止当前的JavaScript CPU性能分析会话 。以console.profile作为一个例子。
16、console.table()
定义:displays the data in a table form.The data argument may be an array or an object.
译文:将数据以表格形式打印出。数据参数可能为一个数组,也可能为一个对象。
示例1:
// an array of strings console.table(["apples", "oranges", "bananas"]);
result:
示例2: