Skip to content

Commit

Permalink
[zh-cn] sync translated content (#23146)
Browse files Browse the repository at this point in the history
Co-authored-by: Allo <[email protected]>
  • Loading branch information
mdn-bot and yin1999 authored Aug 19, 2024
1 parent 01e7d11 commit 898f167
Show file tree
Hide file tree
Showing 10 changed files with 79 additions and 80 deletions.
18 changes: 9 additions & 9 deletions files/zh-cn/_redirects.txt
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@
/zh-CN/docs/DOM/XMLHttpRequest/Using_XMLHttpRequest /zh-CN/docs/Web/API/XMLHttpRequest_API/Using_XMLHttpRequest
/zh-CN/docs/DOM/console.dir /zh-CN/docs/Web/API/console/dir_static
/zh-CN/docs/DOM/console.group /zh-CN/docs/Web/API/console/group_static
/zh-CN/docs/DOM/console.groupCollapsed /zh-CN/docs/Web/API/console/groupcollapsed_static
/zh-CN/docs/DOM/console.groupCollapsed /zh-CN/docs/Web/API/console/groupCollapsed_static
/zh-CN/docs/DOM/console.log /zh-CN/docs/Web/API/console/log_static
/zh-CN/docs/DOM/console.trace /zh-CN/docs/Web/API/console/trace_static
/zh-CN/docs/DOM/document /zh-CN/docs/Web/API/Document
Expand Down Expand Up @@ -1934,30 +1934,30 @@
/zh-CN/docs/Web/API/caches /zh-CN/docs/Web/API/Window/caches
/zh-CN/docs/Web/API/console.dir /zh-CN/docs/Web/API/console/dir_static
/zh-CN/docs/Web/API/console.group /zh-CN/docs/Web/API/console/group_static
/zh-CN/docs/Web/API/console.groupCollapsed /zh-CN/docs/Web/API/console/groupcollapsed_static
/zh-CN/docs/Web/API/console.groupCollapsed /zh-CN/docs/Web/API/console/groupCollapsed_static
/zh-CN/docs/Web/API/console.log /zh-CN/docs/Web/API/console/log_static
/zh-CN/docs/Web/API/console.time /zh-CN/docs/Web/API/console/time_static
/zh-CN/docs/Web/API/console.trace /zh-CN/docs/Web/API/console/trace_static
/zh-CN/docs/Web/API/console/assert /zh-CN/docs/Web/API/console/assert_static
/zh-CN/docs/Web/API/console/clear /zh-CN/docs/Web/API/console/clear_static
/zh-CN/docs/Web/API/console/count /zh-CN/docs/Web/API/console/count_static
/zh-CN/docs/Web/API/console/countReset /zh-CN/docs/Web/API/console/countreset_static
/zh-CN/docs/Web/API/console/countReset /zh-CN/docs/Web/API/console/countReset_static
/zh-CN/docs/Web/API/console/debug /zh-CN/docs/Web/API/console/debug_static
/zh-CN/docs/Web/API/console/dir /zh-CN/docs/Web/API/console/dir_static
/zh-CN/docs/Web/API/console/dirxml /zh-CN/docs/Web/API/console/dirxml_static
/zh-CN/docs/Web/API/console/error /zh-CN/docs/Web/API/console/error_static
/zh-CN/docs/Web/API/console/group /zh-CN/docs/Web/API/console/group_static
/zh-CN/docs/Web/API/console/groupCollapsed /zh-CN/docs/Web/API/console/groupcollapsed_static
/zh-CN/docs/Web/API/console/groupEnd /zh-CN/docs/Web/API/console/groupend_static
/zh-CN/docs/Web/API/console/groupCollapsed /zh-CN/docs/Web/API/console/groupCollapsed_static
/zh-CN/docs/Web/API/console/groupEnd /zh-CN/docs/Web/API/console/groupEnd_static
/zh-CN/docs/Web/API/console/info /zh-CN/docs/Web/API/console/info_static
/zh-CN/docs/Web/API/console/log /zh-CN/docs/Web/API/console/log_static
/zh-CN/docs/Web/API/console/profile /zh-CN/docs/Web/API/console/profile_static
/zh-CN/docs/Web/API/console/profileEnd /zh-CN/docs/Web/API/console/profileend_static
/zh-CN/docs/Web/API/console/profileEnd /zh-CN/docs/Web/API/console/profileEnd_static
/zh-CN/docs/Web/API/console/table /zh-CN/docs/Web/API/console/table_static
/zh-CN/docs/Web/API/console/time /zh-CN/docs/Web/API/console/time_static
/zh-CN/docs/Web/API/console/timeEnd /zh-CN/docs/Web/API/console/timeend_static
/zh-CN/docs/Web/API/console/timeLog /zh-CN/docs/Web/API/console/timelog_static
/zh-CN/docs/Web/API/console/timeStamp /zh-CN/docs/Web/API/console/timestamp_static
/zh-CN/docs/Web/API/console/timeEnd /zh-CN/docs/Web/API/console/timeEnd_static
/zh-CN/docs/Web/API/console/timeLog /zh-CN/docs/Web/API/console/timeLog_static
/zh-CN/docs/Web/API/console/timeStamp /zh-CN/docs/Web/API/console/timeStamp_static
/zh-CN/docs/Web/API/console/trace /zh-CN/docs/Web/API/console/trace_static
/zh-CN/docs/Web/API/console/warn /zh-CN/docs/Web/API/console/warn_static
/zh-CN/docs/Web/API/crossOriginIsolated /zh-CN/docs/Web/API/Window/crossOriginIsolated
Expand Down
52 changes: 26 additions & 26 deletions files/zh-cn/_wikihistory.json
Original file line number Diff line number Diff line change
Expand Up @@ -16169,14 +16169,14 @@
"modified": "2020-01-12T03:19:48.000Z",
"contributors": ["853419196", "ZhangKaiqiang"]
},
"Web/API/console/countReset_static": {
"modified": "2020-10-15T22:08:08.444Z",
"contributors": ["Paapaapa", "807573515"]
},
"Web/API/console/count_static": {
"modified": "2019-08-15T04:00:38.089Z",
"contributors": ["teemoooo", "gaowhen"]
},
"Web/API/console/countreset_static": {
"modified": "2020-10-15T22:08:08.444Z",
"contributors": ["Paapaapa", "807573515"]
},
"Web/API/console/debug_static": {
"modified": "2020-10-15T22:15:26.417Z",
"contributors": ["hefang"]
Expand All @@ -16193,18 +16193,18 @@
"modified": "2019-08-15T04:02:05.738Z",
"contributors": ["pluwen", "kameii"]
},
"Web/API/console/group_static": {
"modified": "2019-03-24T00:18:26.661Z",
"contributors": ["teoli", "khalid32", "ziyunfei"]
},
"Web/API/console/groupcollapsed_static": {
"Web/API/console/groupCollapsed_static": {
"modified": "2019-03-24T00:18:28.377Z",
"contributors": ["teoli", "khalid32", "ziyunfei"]
},
"Web/API/console/groupend_static": {
"Web/API/console/groupEnd_static": {
"modified": "2019-03-18T21:46:40.075Z",
"contributors": ["hhxxhg", "luohe"]
},
"Web/API/console/group_static": {
"modified": "2019-03-24T00:18:26.661Z",
"contributors": ["teoli", "khalid32", "ziyunfei"]
},
"Web/API/console/info_static": {
"modified": "2020-02-02T00:13:13.877Z",
"contributors": ["Headog", "tsingwong", "Jaanai-Ewain", "yogoshary"]
Expand All @@ -16224,18 +16224,30 @@
"ziyunfei"
]
},
"Web/API/console/profileEnd_static": {
"modified": "2020-10-15T22:04:42.916Z",
"contributors": ["JQ_Chan"]
},
"Web/API/console/profile_static": {
"modified": "2019-03-18T21:41:07.871Z",
"contributors": ["clwm01"]
},
"Web/API/console/profileend_static": {
"modified": "2020-10-15T22:04:42.916Z",
"contributors": ["JQ_Chan"]
},
"Web/API/console/table_static": {
"modified": "2020-10-15T21:54:27.285Z",
"contributors": ["RainSlide", "dondevi", "eeeeeeeason", "zzw918"]
},
"Web/API/console/timeEnd_static": {
"modified": "2020-10-15T21:50:04.648Z",
"contributors": ["luisleee", "hhxxhg", "Dcfm", "regiondavid"]
},
"Web/API/console/timeLog_static": {
"modified": "2020-10-15T22:16:19.657Z",
"contributors": ["lifankohome", "Reaper622"]
},
"Web/API/console/timeStamp_static": {
"modified": "2019-03-23T22:08:57.552Z",
"contributors": ["tsingwong", "ershing"]
},
"Web/API/console/time_static": {
"modified": "2020-10-15T21:27:17.192Z",
"contributors": [
Expand All @@ -16247,18 +16259,6 @@
"freemen"
]
},
"Web/API/console/timeend_static": {
"modified": "2020-10-15T21:50:04.648Z",
"contributors": ["luisleee", "hhxxhg", "Dcfm", "regiondavid"]
},
"Web/API/console/timelog_static": {
"modified": "2020-10-15T22:16:19.657Z",
"contributors": ["lifankohome", "Reaper622"]
},
"Web/API/console/timestamp_static": {
"modified": "2019-03-23T22:08:57.552Z",
"contributors": ["tsingwong", "ershing"]
},
"Web/API/console/trace_static": {
"modified": "2020-10-15T21:04:54.511Z",
"contributors": ["zhangchen", "airt", "teoli", "jsx", "ziyunfei"]
Expand Down
2 changes: 1 addition & 1 deletion files/zh-cn/web/api/console/countreset_static/index.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: console:countReset() 静态方法
slug: Web/API/console/countreset_static
slug: Web/API/console/countReset_static
---

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

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

{{APIRef("Console API")}}
Expand Down
75 changes: 37 additions & 38 deletions files/zh-cn/web/api/console/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ title: console
slug: Web/API/console
---

{{APIRef("Console API")}}
{{APIRef("Console API")}} {{AvailableInWorkers}}

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

Expand All @@ -13,19 +13,15 @@ slug: Web/API/console
console.log("Failed to open the specified link");
```

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

{{AvailableInWorkers}}

## 方法
## 实例方法

- {{domxref("console/assert_static", "console.assert()")}}
- : 如果第一个参数为 `false` ,则将消息和堆栈跟踪记录到控制台。
- : 如果第一个参数为 `false`,则将消息和堆栈跟踪记录到控制台。
- {{domxref("console.clear_static", "console.clear()")}}
- : 清空控制台,并输出 `Console was cleared`
- : 清空控制台。
- {{domxref("console.count_static", "console.count()")}}
- : 以参数为标识记录调用的次数,调用时在控制台打印标识以及调用次数。
- {{domxref("console.countreset_static", "console.countReset()")}}
- {{domxref("console.countReset_static", "console.countReset()")}}
- : 重置指定标签的计数器值。
- {{domxref("console.debug_static", "console.debug()")}}
- : 在控制台打印一条 `"debug"` 级别的消息。
Expand All @@ -39,27 +35,27 @@ console.log("Failed to open the specified link");
- : `error()` 方法的别称。
- {{domxref("console.group_static", "console.group()")}}
- : 创建一个新的内联[分组](#在_console_中使用编组), 后续所有打印内容将会以子层级的形式展示。调用 `groupEnd()`来闭合组。
- {{domxref("console.groupcollapsed_static", "console.groupCollapsed()")}}
- {{domxref("console.groupCollapsed_static", "console.groupCollapsed()")}}
- : 创建一个新的内联[分组](#在_console_中使用编组)。使用方法和 `group()` 相同,不同的是,`groupCollapsed()` 方法打印出来的内容默认是折叠的。调用`groupEnd()`来闭合组。
- {{domxref("console.groupend_static", "console.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}}
- {{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_static", "console.time()")}}
- : 启动一个以入参作为特定名称的[定时器](#定时器),在显示页面中可同时运行的定时器上限为 10,000.
- {{domxref("console.timeend_static", "console.timeEnd()")}}
- {{domxref("console.timeEnd_static", "console.timeEnd()")}}
- : 结束特定的[定时器](#定时器)并以毫秒打印其从开始到结束所用的时间。
- {{domxref("console.timelog_static", "console.timeLog()")}}
- {{domxref("console.timeLog_static", "console.timeLog()")}}
- : 打印特定[定时器](#定时器)所运行的时间。
- {{domxref("console.timestamp_static", "console.timeStamp()")}} {{Non-standard_inline}}
- {{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()")}}
- : 输出[堆栈跟踪](#堆栈跟踪)
Expand All @@ -76,33 +72,33 @@ console 对象中较多使用的主要有四个方法 {{domxref("console.log_sta

#### 打印单个对象

The simplest way to use the logging methods is to output a single object:
使用日志记录方法的最简单方式是输出单个对象:

```js
var someObject = { str: "Some text", id: 5 };
const someObject = { str: "一些文本", id: 5 };
console.log(someObject);
```

打印结果类似下面:

```
[09:27:13.475] ({str:"Some text", id:5})
```plain
{str:"一些文本", id:5}
```

#### 打印多个对象

可以打印多个对象,就像下面一样:

```js
var car = "Dodge Charger";
var someObject = { str: "Some text", id: 5 };
console.info("My first car was a", car, ". The object is:", someObject);
const car = "道奇战马";
const someObject = { str: "一些文本", id: 5 };
console.info("我的第一辆车是", car, "。该对象为:", someObject);
```

打印结果类似下面:

```
[09:28:22.711] My first car was a Dodge Charger . The object is: ({str:"Some text", id:5})
```plain
我的第一辆车是 道奇战马。该对象为: {str:"一些文本", id:5}
```

#### 使用字符串替换
Expand All @@ -121,20 +117,20 @@ console.info("My first car was a", car, ". The object is:", someObject);
当要替换的参数类型和预期的打印类型不同时,参数会被转换成预期的打印类型。

```
for (var i=0; i<5; i++) {
console.log("Hello, %s. You've called me %d times.", "Bob", i+1);
```js
for (let i = 0; i < 5; i++) {
console.log("你好,%s。你已经联系我 %d 次了。", "小明", i + 1);
}
```

输出样例如下所示:

```
[13:14:13.481] Hello, Bob. You've called me 1 times.
[13:14:13.483] Hello, Bob. You've called me 2 times.
[13:14:13.485] Hello, Bob. You've called me 3 times.
[13:14:13.487] Hello, Bob. You've called me 4 times.
[13:14:13.488] Hello, Bob. You've called me 5 times.
```plain
你好,小明。你已经联系我 1 次了。
你好,小明。你已经联系我 2 次了。
你好,小明。你已经联系我 3 次了。
你好,小明。你已经联系我 4 次了。
你好,小明。你已经联系我 5 次了。
```

#### 为控制台定义样式
Expand All @@ -148,7 +144,9 @@ console.log(
);
```

指令前的文本不会受到影响,但指令后的文本将会使用参数中声明的 CSS 样式。![](css-styling.png)
指令前的文本不会受到影响,但指令后的文本将会使用参数中声明的 CSS 样式。

![Firefox 控制台中添加了样式的文本](css-styling.png)

`%c` 语法可用的属性如下 (至少在 Firefox 中是这样,别的浏览器会有诸多不同):

Expand All @@ -171,7 +169,8 @@ console.log(
- {{cssxref("word-spacing")}} 和 {{cssxref("word-break")}}
- {{cssxref("writing-mode")}}

**注意**:控制台信息的默认行为与行内元素相似。为了应用 `padding``margin` 这类效果,你应当这样设置`display: inline-block`
> [!NOTE]
> 控制台信息的默认行为与行内元素相似。为了应用 `padding``margin` 这类效果,你应当将 `display` 属性设置为 `display: inline-block`
### 在 console 中使用编组

Expand All @@ -194,7 +193,7 @@ console.debug("Back to the outer level");

执行结果:

![Demo of nested groups in Firefox console](console_groups_demo.png)
![Firefox 控制台中的嵌套编组演示](console_groups_demo.png)

### 计时器

Expand All @@ -212,7 +211,7 @@ console.timeEnd("answer time");

这段代码将会打印需要用户关闭 alert box 的时间,打印时间到控制台上,等用户关闭第二个 alert 后,把结束时间打印到控制台。

![timerresult.png](console-timelog.png)
![Firefox 控制台的时间记录](console-timelog.png)

注意无论在开始还是结束的时候都会打印计时器的名字。

Expand All @@ -236,7 +235,7 @@ foo();

控制台的输出:

![](api-trace2.png)
![Firefox 控制台的堆栈跟踪](api-trace2.png)

## 规范

Expand Down
2 changes: 1 addition & 1 deletion files/zh-cn/web/api/console/profileend_static/index.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: console:profileEnd() 静态方法
slug: Web/API/console/profileend_static
slug: Web/API/console/profileEnd_static
---

{{APIRef("Console API")}}{{Non-standard_header}}
Expand Down
2 changes: 1 addition & 1 deletion files/zh-cn/web/api/console/timeend_static/index.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: console:timeEnd() 静态方法
slug: Web/API/console/timeend_static
slug: Web/API/console/timeEnd_static
---

{{APIRef("Console API")}}{{Non-standard_header}}
Expand Down
2 changes: 1 addition & 1 deletion files/zh-cn/web/api/console/timelog_static/index.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: console:timeLog() 静态方法
slug: Web/API/console/timelog_static
slug: Web/API/console/timeLog_static
---

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

{{APIRef("Console API")}}{{Non-standard_header}}
Expand Down

0 comments on commit 898f167

Please sign in to comment.