From 33058f2b292b3a581333bdfb21b8f671898c5060 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:40:17 -0500 Subject: initial commit --- files/zh-cn/web/api/console_api/index.html | 68 ++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 files/zh-cn/web/api/console_api/index.html (limited to 'files/zh-cn/web/api/console_api') diff --git a/files/zh-cn/web/api/console_api/index.html b/files/zh-cn/web/api/console_api/index.html new file mode 100644 index 0000000000..bf02731963 --- /dev/null +++ b/files/zh-cn/web/api/console_api/index.html @@ -0,0 +1,68 @@ +--- +title: Console API +slug: Web/API/Console_API +translation_of: Web/API/Console_API +--- +
{{DefaultAPISidebar("Console API")}}
+ +

Console API提供了允许开发人员执行调试任务的功能,例如在代码中的某个位置记录消息或变量值,或者计算任务完成所需的时间。

+ +

概念和用法

+ +

Console API最初是一个专有的API,不同的浏览器以自己的试下方式来实现它. Console API  规范统一了这个API的行为, 并且所有现代浏览器最终都决定实现这种行为 — 尽管一些实现仍然有自己的附加专有功能. 了解这些请查看:

+ + + +

用法非常简单 — {{domxref("console")}} 对象 — 可以通过{{domxref("window.console")}}获取到, 在workers里面使用{{domxref("WorkerGlobalScope.console")}}获取,console — 包含许多方法,您可以调用它们来执行基本的调试任务, 通常专注于将各种值记录到浏览器中 WEB控制台.

+ +

到目前为止,最常用的方法是console.log,它用于记录特定变量中包含的当前值.

+ +

接口

+ +
+
{{domxref("console")}}
+
提供基本的调试功能,包括日志记录,堆栈跟踪,计时器和计数器。
+
+ +

示例

+ +
let myString = 'Hello world';
+
+// Output "Hello world" to the console
+console.log(myString)
+ +

Console reference page查看更多示例

+ +

规范

+ + + + + + + + + + + + + + +
SpecificationStatusComment
{{SpecName('Console API')}}{{Spec2('Console API')}}Initial definition.
+ +

浏览器兼容性

+ + + +

{{Compat("api.Console")}}

+ +

其他

+ + -- cgit v1.2.3-54-g00ecf