Skip to content

Commit

Permalink
zh-cn: sync upstream changes
Browse files Browse the repository at this point in the history
  • Loading branch information
yin1999 committed Nov 15, 2023
1 parent 01b3098 commit 1b3a21f
Show file tree
Hide file tree
Showing 22 changed files with 131 additions and 143 deletions.
9 changes: 4 additions & 5 deletions files/zh-cn/web/api/console/assert_static/index.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
---
title: Console.assert()
title: console:assert() 静态方法
slug: Web/API/console/assert_static
original_slug: Web/API/console/assert
---

{{APIRef("Console API")}}
Expand All @@ -10,7 +9,7 @@ original_slug: Web/API/console/assert

{{AvailableInWorkers}}

`console.assert()`方法在 Node.js 中的实现和浏览器中可用的`console.assert()`方法实现是不同的。在浏览器中当`console.assert()`方法接受到一个值为假断言的时候,会向控制台输出传入的内容,但是并不会中断代码的执行,而在 Node.js v10.0.0 之前,一个值为假的断言也将会导致一个`AssertionError`被抛出,使得代码执行被打断。v10.0.0 修复了此差异,所以现在`console.assert()`在 Node 和浏览器中执行行为相同。
`console.assert()` 方法在 Node.js 中的实现和浏览器中可用的 `console.assert()` 方法实现是不同的。在浏览器中当 `console.assert()` 方法接受到一个值为假断言的时候,会向控制台输出传入的内容,但是并不会中断代码的执行,而在 Node.js v10.0.0 之前,一个值为假的断言也将会导致一个 `AssertionError` 被抛出,使得代码执行被打断。v10.0.0 修复了此差异,所以现在 `console.assert()` 在 Node 和浏览器中执行行为相同。

## 语法

Expand Down Expand Up @@ -58,7 +57,7 @@ console.log("the word is %s try number %d", "foo", 123);
// 输出:the word is foo try number 123
```

`但是 console.assert` 在不同浏览器中可能获得不同的效果:
但是 `console.assert` 在不同浏览器中可能获得不同的效果:

```js
console.assert(false, "the word is %s", "foo");
Expand All @@ -70,7 +69,7 @@ console.assert(false, "the word is %s", "foo");
// Assertion failed: the word is %s foo
```

有关详细信息,请参阅 {{Domxref("console")}} 文档中的 [输出文本到控制台](/zh-CN/docs/Web/API/Console#%E8%BE%93%E5%87%BA%E6%96%87%E6%9C%AC%E5%88%B0%E6%8E%A7%E5%88%B6%E5%8F%B0)
有关详细信息,请参阅 {{Domxref("console")}} 文档中的 [输出文本到控制台](/zh-CN/docs/Web/API/console#输出文本到控制台)

## 规范

Expand Down
5 changes: 2 additions & 3 deletions files/zh-cn/web/api/console/clear_static/index.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
---
title: clear()
title: console:clear() 静态方法
slug: Web/API/console/clear_static
original_slug: Web/API/console/clear
---

{{APIRef("Console API")}}
Expand All @@ -20,7 +19,7 @@ clear();

### 返回值

({{jsxref("undefined")}})
{{jsxref("undefined")}}

## 规范

Expand Down
5 changes: 2 additions & 3 deletions files/zh-cn/web/api/console/count_static/index.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
---
title: console:count() 方法
title: console:count() 静态方法
slug: Web/API/console/count_static
original_slug: Web/API/console/count
---

{{APIRef("Console API")}}
Expand All @@ -24,7 +23,7 @@ count(label)

### 返回值

({{jsxref("undefined")}})
{{jsxref("undefined")}}

## 示例

Expand Down
14 changes: 7 additions & 7 deletions files/zh-cn/web/api/console/countreset_static/index.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
---
title: Console.countReset()
title: console:countReset() 静态方法
slug: Web/API/console/countreset_static
original_slug: Web/API/console/countReset
---

{{APIRef("Console API")}}
Expand All @@ -16,8 +15,9 @@ original_slug: Web/API/console/countReset

## 语法

```
console.countReset([label]);
```js-nolint
countReset()
countReset(label)
```

### 参数
Expand All @@ -42,7 +42,7 @@ default: 0

### 异常情况

若传入一个不存在的 `label`, `countReset` 返回下面的警告信息:
若传入一个不存在的 `label``countReset` 返回下面的警告信息:

```
Counter "counter-name" doesn’t exist.
Expand Down Expand Up @@ -120,10 +120,10 @@ console.count("alice");

调用 countReset("bod") 只是重置了 "bob" 的计数器值 而 "alice" 的计数器值没有改变。

## Specifications
## 规范

{{Specifications}}

## Browser compatibility
## 浏览器兼容性

{{Compat}}
3 changes: 1 addition & 2 deletions files/zh-cn/web/api/console/debug_static/index.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
---
title: Console.debug()
title: console:debug() 静态方法
slug: Web/API/console/debug_static
original_slug: Web/API/console/debug
---

{{APIRef("Console API")}}
Expand Down
5 changes: 2 additions & 3 deletions files/zh-cn/web/api/console/dir_static/index.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
---
title: console.dir
title: consoledir() 静态方法
slug: Web/API/console/dir_static
original_slug: Web/API/console/dir
---

{{APIRef("Console API")}}
Expand All @@ -27,7 +26,7 @@ dir(object);

### 返回值

({{jsxref("undefined")}})
{{jsxref("undefined")}}

## 规范

Expand Down
3 changes: 1 addition & 2 deletions files/zh-cn/web/api/console/dirxml_static/index.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
---
title: Console.dirxml()
title: console:dirxml() 静态方法
slug: Web/API/console/dirxml_static
original_slug: Web/API/console/dirxml
---

{{APIRef("Console API")}}{{Non-standard_header}}
Expand Down
2 changes: 1 addition & 1 deletion files/zh-cn/web/api/console/error_static/index.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
title: Console.error()
title: console:error() 静态方法
slug: Web/API/console/error_static
original_slug: Web/API/console/error
---
Expand Down
3 changes: 1 addition & 2 deletions files/zh-cn/web/api/console/group_static/index.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
---
title: console.group()
title: consolegroup() 静态方法
slug: Web/API/console/group_static
original_slug: Web/API/console/group
---

{{APIRef("Console API")}}
Expand Down
3 changes: 1 addition & 2 deletions files/zh-cn/web/api/console/groupcollapsed_static/index.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
---
title: console.groupCollapsed()
title: consolegroupCollapsed() 静态方法
slug: Web/API/console/groupcollapsed_static
original_slug: Web/API/console/groupCollapsed
---

{{APIRef("Console API")}}
Expand Down
13 changes: 6 additions & 7 deletions files/zh-cn/web/api/console/groupend_static/index.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
---
title: Console.groupEnd()
title: console:groupEnd() 静态方法
slug: Web/API/console/groupend_static
original_slug: Web/API/console/groupEnd
---

{{APIRef("Console API")}}
Expand All @@ -12,22 +11,22 @@ original_slug: Web/API/console/groupEnd

## 语法

```plain
console.groupEnd();
```js-nolint
groupEnd()
```

## 参数

None.
无。

## Specifications
## 规范

{{Specifications}}

## 浏览器兼容性

{{Compat}}

## See also
## 参见

- [Opera Dragonfly documentation: Console](http://www.opera.com/dragonfly/documentation/console/)
96 changes: 47 additions & 49 deletions files/zh-cn/web/api/console/index.md
Original file line number Diff line number Diff line change
@@ -1,78 +1,76 @@
---
title: Console
title: console
slug: Web/API/console
---

{{APIRef("Console API")}}

**`Console`** 对象提供了浏览器控制台调试的接口(如:Firefox 的 [Web Console](/zh-CN/docs/Tools/Web_Console))。在不同浏览器上它的工作方式可能不一样,但通常都会提供一套共性的功能。
**`console`** 对象提供了浏览器控制台调试的接口(如:Firefox 的 [Web console](https://firefox-source-docs.mozilla.org/devtools-user/web_console/index.html))。在不同浏览器上它的工作方式可能不一样,但通常都会提供一套共性的功能。

`Console` 对象可以从任何全局对象中访问到,如 浏览器作用域上的 {{domxref("Window")}},以及通过属性控制台作为 workers 中的特定变体的 {{domxref("WorkerGlobalScope")}}。可以通过 {{domxref("Window.console")}} 引用,也可以简单的通过 `console` 引用。例:
`console` 对象可以从任何全局对象中访问到,如 浏览器作用域上的 {{domxref("Window")}},以及通过属性控制台作为 worker 中的特定变体的 {{domxref("WorkerGlobalScope")}}。可以通过 {{domxref("Window.console")}} 引用,也可以简单的通过 `console` 引用。例:

```js
console.log("Failed to open the specified link");
```

本页面记录了 `Console` 对象上的[方法](#方法)并给出了几个 [Usage](#usage) (用例)。
本页面记录了 `console` 对象上的[方法](#方法)并给出了几个 [Usage](#usage) (用例)。

{{AvailableInWorkers}}

> **备注:** 实际的 `console` 接口被定义为全小写的形式(比如不是这种形式 `Console` ),这是历史原因导致的。
## 方法

- {{domxref("Console.assert()")}}
- {{domxref("console/assert_static", "console.assert()")}}
- : 如果第一个参数为 `false` ,则将消息和堆栈跟踪记录到控制台。
- {{domxref("Console.clear()")}}
- {{domxref("console.clear_static", "console.clear()")}}
- : 清空控制台,并输出 `Console was cleared`
- {{domxref("Console.count()")}}
- {{domxref("console.count_static", "console.count()")}}
- : 以参数为标识记录调用的次数,调用时在控制台打印标识以及调用次数。
- {{domxref("Console.countReset()")}}
- {{domxref("console.countreset_static", "console.countReset()")}}
- : 重置指定标签的计数器值。
- {{domxref("Console.debug()")}}
- {{domxref("console.debug_static", "console.debug()")}}
- : 在控制台打印一条 `"debug"` 级别的消息。
- {{domxref("Console.dir()")}}
- : 显示一个由特定的 Javascript 对象列表组成的可交互列表。这个列表可以使用三角形隐藏和显示来审查子对象的内容。.
- {{domxref("Console.dirxml()")}}
- {{domxref("console.dir_static", "console.dir()")}}
- : 显示一个由特定的 Javascript 对象列表组成的可交互列表。这个列表可以使用三角形隐藏和显示来审查子对象的内容。
- {{domxref("console.dirxml_static", "console.dirxml()")}}
- : 打印 XML/HTML 元素表示的指定对象,否则显示 JavaScript 对象视图。
- {{domxref("Console.error()")}}
- : 打印一条错误信息,使用方法可以参考 [string substitution](/zh-CN/docs/Web/API/console#Using_string_substitutions)
- {{domxref("Console.exception()")}} {{Non-standard_inline}} {{deprecated_inline}}
- {{domxref("console.error_static", "console.error()")}}
- : 打印一条错误信息,使用方法可以参考[使用字符串替换](#使用字符串替换)
- `console.exception()` {{Non-standard_inline}} {{deprecated_inline}}
- : `error()` 方法的别称。
- {{domxref("Console.group()")}}
- : 创建一个新的内联 [group](/zh-CN/docs/Web/API/console#Using_groups_in_the_console), 后续所有打印内容将会以子层级的形式展示。调用 `groupEnd()`来闭合组。
- {{domxref("Console.groupCollapsed()")}}
- : 创建一个新的内联 [group](/zh-CN/docs/Web/API/console#Using_groups_in_the_console)。使用方法和 `group()` 相同,不同的是,`groupCollapsed()` 方法打印出来的内容默认是折叠的。调用`groupEnd()`来闭合组。
- {{domxref("Console.groupEnd()")}}
- : 闭合当前内联 [group](/zh-CN/docs/Web/API/console#Using_groups_in_the_console)
- {{domxref("Console.info()")}}
- : 打印资讯类说明信息,使用方法可以参考 [string substitution](/zh-CN/docs/Web/API/console#Using_string_substitutions)
- {{domxref("Console.log()")}}
- : 打印内容的通用方法,使用方法可以参考 [string substitution](/zh-CN/docs/Web/API/console#Using_string_substitutions)
- {{domxref("Console.profile()")}} {{Non-standard_inline}}
- : Starts the browser's built-in profiler (for example, the [Firefox performance tool](/zh-CN/docs/Tools/Performance)). You can specify an optional name for the profile.
- {{domxref("Console.profileEnd()")}} {{Non-standard_inline}}
- : Stops the profiler. You can see the resulting profile in the browser's performance tool (for example, the [Firefox performance tool](/zh-CN/docs/Tools/Performance)).
- {{domxref("Console.table()")}}
- {{domxref("console.group_static", "console.group()")}}
- : 创建一个新的内联[分组](#在_console_中使用编组), 后续所有打印内容将会以子层级的形式展示。调用 `groupEnd()`来闭合组。
- {{domxref("console.groupcollapsed_static", "console.groupCollapsed()")}}
- : 创建一个新的内联[分组](#在_console_中使用编组)。使用方法和 `group()` 相同,不同的是,`groupCollapsed()` 方法打印出来的内容默认是折叠的。调用`groupEnd()`来闭合组。
- {{domxref("console.groupend_static", "console.groupEnd()")}}
- : 闭合当前内联[分组](#在_console_中使用编组)
- {{domxref("console.info_static", "console.info()")}}
- : 打印资讯类说明信息,使用方法可以参考[使用字符串替换](#使用字符串替换)
- {{domxref("console.log_static", "console.log()")}}
- : 打印内容的通用方法,使用方法可以参考[使用字符串替换](#使用字符串替换)
- {{domxref("console.profile_static", "console.profile()")}} {{Non-standard_inline}}
- : Starts the browser's built-in profiler (for example, the [Firefox performance tool](https://firefox-source-docs.mozilla.org/devtools-user/performance/index.html)). You can specify an optional name for the profile.
- {{domxref("console.profileend_static", "console.profileEnd()")}} {{Non-standard_inline}}
- : Stops the profiler. You can see the resulting profile in the browser's performance tool (for example, the [Firefox performance tool](https://firefox-source-docs.mozilla.org/devtools-user/performance/index.html)).
- {{domxref("console.table_static", "console.table()")}}
- : 将列表型的数据打印成表格。
- {{domxref("Console.time()")}}
- : 启动一个以入参作为特定名称的[计时器](/zh-CN/docs/Web/API/console#Timers),在显示页面中可同时运行的计时器上限为 10,000.
- {{domxref("Console.timeEnd()")}}
- : 结束特定的 [计时器](/zh-CN/docs/Web/API/console#Timers) 并以毫秒打印其从开始到结束所用的时间。
- {{domxref("Console.timeLog()")}}
- : 打印特定 [计时器](/zh-CN/docs/Web/API/console#Timers) 所运行的时间。
- {{domxref("Console.timeStamp()")}} {{Non-standard_inline}}
- : 添加一个标记到浏览器的 [Timeline](https://developer.chrome.com/devtools/docs/timeline)[Waterfall](/zh-CN/docs/Tools/Performance/Waterfall) 工具。
- {{domxref("Console.trace()")}}
- : 输出一个 [stack trace](/zh-CN/docs/Web/API/console#Stack_traces)
- {{domxref("Console.warn()")}}
- : 打印一个警告信息,可以使用 [string substitution](/zh-CN/docs/Web/API/console#Using_string_substitutions) 和额外的参数。
- {{domxref("console.time_static", "console.time()")}}
- : 启动一个以入参作为特定名称的[定时器](#定时器),在显示页面中可同时运行的定时器上限为 10,000.
- {{domxref("console.timeend_static", "console.timeEnd()")}}
- : 结束特定的[定时器](#定时器)并以毫秒打印其从开始到结束所用的时间。
- {{domxref("console.timelog_static", "console.timeLog()")}}
- : 打印特定[定时器](#定时器)所运行的时间。
- {{domxref("console.timestamp_static", "console.timeStamp()")}} {{Non-standard_inline}}
- : 添加一个标记到浏览器的 [Timeline](https://developer.chrome.com/devtools/docs/timeline)[Waterfall](https://profiler.firefox.com/docs/) 工具。
- {{domxref("console.trace_static", "console.trace()")}}
- : 输出[堆栈跟踪](#堆栈跟踪)
- {{domxref("console.warn_static", "console.warn()")}}
- : 打印一个警告信息,可以使用[字符串替换](#使用字符串替换)和额外的参数。

## 示例

### 输出文本到控制台

console 对象中较多使用的主要有四个方法 {{domxref("console.log()")}}, {{domxref("console.info()")}}, {{domxref("console.warn()")}}, 和{{domxref("console.error()")}}。每一个结果在日志中都有不同的样式,可以使用浏览器控制台的日志筛选功能筛选出感兴趣的日志信息。
console 对象中较多使用的主要有四个方法 {{domxref("console.log_static", "console.log()")}}{{domxref("console.info_static", "console.info()")}}{{domxref("console.warn_static", "console.warn()")}} 和{{domxref("console.error_static", "console.error()")}}。每一个结果在日志中都有不同的样式,可以使用浏览器控制台的日志筛选功能筛选出感兴趣的日志信息。

有两种途径使用这些方法,可以简单的传入一组对象,其中的字符串对象会被连接到一起,输出到控制台。或者可以传入包含零个或多个的替换的字符串,后面跟着被替换的对象列表。

Expand Down Expand Up @@ -221,7 +219,7 @@ console.timeEnd("answer time");
### 堆栈跟踪

控制台也支持输出堆栈,其将会显示到调用 {{domxref("console.trace()")}} 的点的调用路径。如下所示:
控制台也支持输出堆栈,其将会显示到调用 {{domxref("console.trace_static")}} 的点的调用路径。如下所示:

```js
function foo() {
Expand Down Expand Up @@ -252,9 +250,9 @@ foo();

## 相关文档

- [Tools](/zh-CN/docs/Tools)
- [Web Console](/zh-CN/docs/Tools/Web_Console) - Firefox 浏览器控制台如何处理 console API 的调用
- [Remote debugging](/zh-CN/docs/Tools/Remote_Debugging) - 如何在调试移动设备时查看控制台输出。
- [Tools](https://firefox-source-docs.mozilla.org/devtools-user/index.html)
- [Web Console](https://firefox-source-docs.mozilla.org/devtools-user/web_console/index.html) - Firefox 浏览器控制台如何处理 console API 的调用
- [Remote debugging](https://profiler.firefox.com/docs/) - 如何在调试移动设备时查看控制台输出。

### 其他实现

Expand Down
11 changes: 6 additions & 5 deletions files/zh-cn/web/api/console/info_static/index.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
---
title: Console.info()
title: console:info() 静态方法
slug: Web/API/console/info_static
original_slug: Web/API/console/info
---

{{APIRef("Console API")}}
Expand All @@ -12,9 +11,11 @@ original_slug: Web/API/console/info

## 语法

```
console.info(obj1 [, obj2, ..., objN]);
console.info(msg [, subst1, ..., substN]);
```js-nolint
info(obj1)
info(obj1, /* …, */ objN)
info(msg)
info(msg, subst1, /* …, */ substN)
```

## 参数
Expand Down
3 changes: 1 addition & 2 deletions files/zh-cn/web/api/console/log_static/index.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
---
title: console.log
title: consolelog() 静态方法
slug: Web/API/console/log_static
original_slug: Web/API/console/log
---

{{APIRef("Console API")}}
Expand Down
Loading

0 comments on commit 1b3a21f

Please sign in to comment.