From 34d0193428d296ce27c832d1613b06f2aeb48e1d Mon Sep 17 00:00:00 2001 From: yaochaonan Date: Tue, 9 May 2023 01:36:56 +0000 Subject: [PATCH] Fix console/timer description Issue:https://gitee.com/openharmony/docs/issues/I6YTM4 Signed-off-by: yaochaonan Change-Id: Idcf9c59f43ec3710d727b81bfcfe6c4e81654b67 --- zh-cn/1.diff | 541 ++++++++++++++++++ .../reference/apis/js-apis-logs.md | 169 +++--- .../reference/apis/js-apis-timer.md | 66 +-- 3 files changed, 670 insertions(+), 106 deletions(-) create mode 100644 zh-cn/1.diff diff --git a/zh-cn/1.diff b/zh-cn/1.diff new file mode 100644 index 0000000000..35f417962d --- /dev/null +++ b/zh-cn/1.diff @@ -0,0 +1,541 @@ +diff --git a/zh-cn/application-dev/reference/apis/js-apis-logs.md b/zh-cn/application-dev/reference/apis/js-apis-logs.md +index 31dd38d1423d394442eafa6978746e051941944a..e13eb4bbbdf8c51c03bac40ef75d53dbf88480aa 100644 +--- a/zh-cn/application-dev/reference/apis/js-apis-logs.md ++++ b/zh-cn/application-dev/reference/apis/js-apis-logs.md +@@ -1,8 +1,6 @@ +-# console (日志打印) ++# console 控制台 + +-本模块提供基础的日志打印能力,支持按照日志级别打印日志信息。 +- +-如果需要使用更高级的日志打印服务,比如按照指定标识筛选日志内容,推荐使用[`@ohos.hilog`](js-apis-hilog.md)。 ++本模块提供了一个简单的调试控制台,类似于浏览器提供的JavaScript控制台机制。 + + > **说明:** + > +@@ -10,9 +8,9 @@ + + ## console.debug + +-debug(message: string): void ++debug(message: string, ...arguments: any[]): void + +-打印debug级别的日志信息。 ++打印调试信息。可以传入多个参数,其中第一个用作主要消息,所有其他参数用作替换值。 + + **系统能力:** SystemCapability.ArkUI.ArkUI.Full + +@@ -21,13 +19,24 @@ debug(message: string): void + | 参数名 | 类型 | 必填 | 说明 | + | ------- | ------ | ---- | ----------- | + | message | string | 是 | 表示要打印的文本信息。 | ++| arguments | any | 否 | 表示要打印的信息。 | + ++**示例:** ++```js ++const number = 5; ++console.debug('count: %d', number); ++// count: 5 ++console.debug('count:', number); ++// count: 5 ++console.debug('count:'); ++// count: ++``` + + ## console.log + +-log(message: string): void ++log(message: string, ...arguments: any[]): void + +-打印debug级别的日志信息。 ++打印日志信息。可以传入多个参数,其中第一个用作主要消息,所有其他参数用作替换值。用法同console.debug()。 + + **系统能力:** SystemCapability.ArkUI.ArkUI.Full + +@@ -36,13 +45,13 @@ log(message: string): void + | 参数名 | 类型 | 必填 | 说明 | + | ------- | ------ | ---- | ----------- | + | message | string | 是 | 表示要打印的文本信息。 | +- ++| arguments | any | 否 | 表示要打印的信息。 | + + ## console.info + +-info(message: string): void ++info(message: string, ...arguments: any[]): void + +-打印info级别的日志信息。 ++打印日志信息(console.log()的别名)。可以传入多个参数,其中第一个用作主要消息,所有其他参数用作替换值。用法同console.debug()。 + + **系统能力:** SystemCapability.ArkUI.ArkUI.Full + +@@ -51,13 +60,13 @@ info(message: string): void + | 参数名 | 类型 | 必填 | 说明 | + | ------- | ------ | ---- | ----------- | + | message | string | 是 | 表示要打印的文本信息。 | +- ++| arguments | any | 否 | 表示要打印的信息。 | + + ## console.warn + +-warn(message: string): void ++warn(message: string, ...arguments: any[]): void + +-打印warn级别的日志信息。 ++打印警告信息。可以传入多个参数,其中第一个用作主要消息,所有其他参数用作替换值。用法同console.debug()。 + + **系统能力:** SystemCapability.ArkUI.ArkUI.Full + +@@ -66,13 +75,13 @@ warn(message: string): void + | 参数名 | 类型 | 必填 | 说明 | + | ------- | ------ | ---- | ----------- | + | message | string | 是 | 表示要打印的文本信息。 | +- ++| arguments | any | 否 | 表示要打印的信息。 | + + ## console.error + +-error(message: string): void ++error(message: string, ...arguments: any[]): void + +-打印error级别的日志信息。 ++打印错误信息。可以传入多个参数,其中第一个用作主要消息,所有其他参数用作替换值。用法同console.debug()。 + + **系统能力:** SystemCapability.ArkUI.ArkUI.Full + +@@ -81,30 +90,15 @@ error(message: string): void + | 参数名 | 类型 | 必填 | 说明 | + | ------- | ------ | ---- | ----------- | + | message | string | 是 | 表示要打印的文本信息。 | ++| arguments | any | 否 | 表示要打印的信息。 | + + +-**示例:** +- +-``` +-export default { +- clickConsole(){ +- var versionCode = 1; +- console.info('Hello World. The current version code is ' + versionCode); +- console.log(`versionCode: ${versionCode}`); +- // 以下写法从API Version 6开始支持console.log('versionCode:%d.', versionCode); +- } +-} +-``` +- +-在DevEco Studio的底部,切换到“HiLog”窗口。选择当前的设备及进程,日志级别选择Info,搜索内容设置为“Hello World”。此时窗口仅显示符合条件的日志,效果如图所示: +- +-![zh-cn_image_0000001200913929](figures/zh-cn_image_0000001200913929.png) +- + ## console.assert10+ + + assert(value?: Object, ...arguments: Object[]): void + +-若value为假,打印后续内容。 ++若value为假(false)或者省略,则console.assert()打印"Assertion failed"这条消息。 ++如果 value 为真值(true),则什么也不会发生。 + + **系统能力:** SystemCapability.Utils.Lang + +@@ -112,15 +106,16 @@ assert(value?: Object, ...arguments: Object[]): void + + | 参数名 | 类型 | 必填 | 说明 | + | ------- | ------ | ---- | ----------- | +-| value | Object | 否 | 值 | ++| value | Object | 否 | 语句结果值。省略则打印"Assertion failed"。| + | arguments | Object | 否 | 错误消息打印。 | + + **示例:** +-``` ++```js + console.assert(true, 'does nothing'); ++console.assert(2 % 1 == 0, 'does nothing'); // 表达式结果值为true。 + + console.assert(false, 'console %s work', 'didn\'t'); +-// Assertion console:ohos didn't work ++// Assertion failed: console didn't work + + console.assert(); + // Assertion failed +@@ -129,7 +124,7 @@ console.assert(); + + count(label?: string): void + +-维护一个内部计数器, 并输出调用label的console.count()次数。默认值为'default'。 ++维护一个内部计数器, 调用时,打印此标签名以及对应的计数次数。 + + **系统能力:** SystemCapability.Utils.Lang + +@@ -137,10 +132,11 @@ count(label?: string): void + + | 参数名 | 类型 | 必填 | 说明 | + | ------- | ------ | ---- | ----------- | +-| label | string | 否 | 计数器标签名。 | ++| label | string | 否 | 计数器标签名。默认值为'default'。| ++ + + **示例:** +-``` ++```js + console.count() + // default: 1 + console.count('default') +@@ -150,7 +146,7 @@ console.count('abc') + console.count('xyz') + // xyz: 1 + console.count('abc') +-abc: 2 ++// abc: 2 + console.count() + // default: 3 + ``` +@@ -159,7 +155,7 @@ console.count() + + countReset(label?: string): void + +-清除label名的计数。默认值为'default'。 ++清除指定标签名的计数。 + + **系统能力:** SystemCapability.Utils.Lang + +@@ -167,10 +163,10 @@ countReset(label?: string): void + + | 参数名 | 类型 | 必填 | 说明 | + | ------- | ------ | ---- | ----------- | +-| label | string | 否 | 计数器标签名。 | ++| label | string | 否 | 计数器标签名。默认值为'default'。| + + **示例:** +-``` ++```js + console.count('abc'); + // abc: 1 + console.countReset('abc'); +@@ -190,13 +186,25 @@ dir(dir?: Object): void + + | 参数名 | 类型 | 必填 | 说明 | + | ------- | ------ | ---- | ----------- | +-| dir | Object | 否 | 需要打印内容的对象。 | ++| dir | Object | 否 | 需要打印内容的对象。省略则无任何打印。| ++ ++ ++**示例:** ++```js ++let a = { foo: { bar: { baz: true } }}; ++console.dir(a); ++// Object: {"foo":{"bar":{"baz":true}}} ++ ++console.dir(); // 无打印 ++``` ++ + + ## console.dirxml10+ + + dirxml(...arguments: Object[]): void + + 此方法调用 console.log() 将接收到的参数传给它。此方法不会产生任何 XML 格式。 ++使用方法与console.log()一致。 + + **系统能力:** SystemCapability.Utils.Lang + +@@ -204,14 +212,14 @@ dirxml(...arguments: Object[]): void + + | 参数名 | 类型 | 必填 | 说明 | + | ------- | ------ | ---- | ----------- | +-| arguments | Object | 否 | 要打印的信息。 | ++| arguments | Object | 是 | 要打印的信息。 | + + ## console.group10+ + + group(...arguments: Object[]): void + +-将后续行的缩进增加 groupIndentation 长度的空格。 +-如果提供需要打印的信息,首先先打印信息,没有额外的缩进。 ++默认将后续行的缩进增加一定长度的空格。 ++如果提供需要打印的信息,则首先打印信息,没有额外的缩进。 + + **系统能力:** SystemCapability.Utils.Lang + +@@ -220,11 +228,26 @@ group(...arguments: Object[]): void + | 参数名 | 类型 | 必填 | 说明 | + | ------- | ------ | ---- | ----------- | + | arguments | Object | 否 | 要打印的信息。 | ++ ++**示例:** ++```js ++console.log("outter"); ++// outter ++console.group(); ++console.log("level 1"); ++// level 1 ++console.group("in level1"); ++// in level1 ++console.log("level 2"); ++// level 2 ++``` ++ ++ + ## console.groupCollapsed10+ + + groupCollapsed(...arguments: Object[]): void + +-group的别名。 ++console.group()的别名。使用方法与console.group()一致。 + + **系统能力:** SystemCapability.Utils.Lang + +@@ -238,10 +261,24 @@ group的别名。 + + groupEnd(): void + +-将后续行的缩进减少 groupIndentation 长度的空格。 ++将后续行的缩进减少一定长度的空格。 + + **系统能力:** SystemCapability.Utils.Lang + ++ ++**示例:** ++```js ++console.log("outter"); ++// outter ++console.group(); ++console.log("level 1"); ++// level 1 ++console.groupEnd(); ++console.log("outter"); ++// outter ++``` ++ ++ + ## console.table10+ + + table(tableData?: Object): void +@@ -254,10 +291,10 @@ table(tableData?: Object): void + + | 参数名 | 类型 | 必填 | 说明 | + | ------- | ------ | ---- | ----------- | +-| tableData | Object | 否 | 要打印为表格形式的对象。 | ++| tableData | Object | 否 | 要打印为表格形式的对象。省略则无任何打印。 | + + **示例:** +-``` ++```js + console.table([1, 2, 3]); + // ┌─────────┬────────┐ + // │ (index) │ Values │ +@@ -281,7 +318,7 @@ console.table({ a: [1, 2, 3, 4, 5], b: 5, c: { e: 5 } }); + + time(label?: string): void + +-启动可用于计算操作持续时间的计时器。默认值为'default'。可使用console.timeEnd()关闭计时器并打印结果。 ++启动可用于计算操作持续时间的计时器。可使用console.timeEnd()关闭计时器并打印结果。 + + **系统能力:** SystemCapability.Utils.Lang + +@@ -289,13 +326,13 @@ time(label?: string): void + + | 参数名 | 类型 | 必填 | 说明 | + | ------- | ------ | ---- | ----------- | +-| label | string | 否 | 计时器标识。 | ++| label | string | 否 | 计时器标识。默认值为'default'。 | + + ## console.timeEnd10+ + + timeEnd(label?: string): void + +-停止之前通过调用 console.time() 启动的计时器并将结果打印。默认值为'default'。 ++停止之前通过调用 console.time() 启动的计时器并将结果打印。 + + **系统能力:** SystemCapability.Utils.Lang + +@@ -303,10 +340,10 @@ timeEnd(label?: string): void + + | 参数名 | 类型 | 必填 | 说明 | + | ------- | ------ | ---- | ----------- | +-| label | string | 否 | 计时器标识。 | ++| label | string | 否 | 计时器标识。默认值为'default' | + + **示例:** +-``` ++```js + console.time('abc'); + console.timeEnd('abc'); + // abc: 225.438ms +@@ -324,14 +361,13 @@ timeLog(label?: string, ...arguments: Object[]): void + + | 参数名 | 类型 | 必填 | 说明 | + | ------- | ------ | ---- | ----------- | +-| label | string | 否 | 计时器标识。 | ++| label | string | 否 | 计时器标识。默认值为'default' | + | arguments | Object | 否 | 需要打印的其他日志。 | + + **示例:** +-``` ++```js + console.time('timer1'); +-const value = aaa(); // 返回 17 +-console.timeLog('timer1', value); ++console.timeLog('timer1', 17); + // timer1: 365.227ms 17 + console.timeEnd('timer1'); + // timer1: 513.22ms +@@ -349,10 +385,14 @@ trace(...arguments: Object[]): void + + | 参数名 | 类型 | 必填 | 说明 | + | ------- | ------ | ---- | ----------- | +-| arguments | Object | 否 | 需要打印的其他日志。 | ++| arguments | Object | 否 | 需要打印的其他日志。省略则仅打印堆栈信息。| + + **示例:** +-``` ++```js + console.trace(); ++// Trace: ++ xxxxxxxxxx(当前堆栈信息) + console.trace("Show the trace"); ++// Trace: Show the trace ++ xxxxxxxxxx(当前堆栈信息) + ``` +\ No newline at end of file +diff --git a/zh-cn/application-dev/reference/apis/js-apis-timer.md b/zh-cn/application-dev/reference/apis/js-apis-timer.md +index ae0957a9b4978d69674f4a63fa0b861fc1a3a48b..f1a695eda78ec4f456c4cdb54524a95065ee19d0 100644 +--- a/zh-cn/application-dev/reference/apis/js-apis-timer.md ++++ b/zh-cn/application-dev/reference/apis/js-apis-timer.md +@@ -18,7 +18,7 @@ setTimeout(handler: Function | string, delay?: number, ...arguments: any[]): num + + | 参数名 | 类型 | 必填 | 说明 | + | -------- | -------- | -------- | -------- | +-| handler | Function \| string | 是 | 定时器到期后执行函数。 | ++| handler | Function \| string | 是 | 定时器到期后执行函数。类型为string则不处理。 | + | delay | number | 否 | 延迟的毫秒数,函数的调用会在该延迟之后发生。如果省略该参数,delay取默认值0,意味着“马上”执行,或尽快执行。 | + | ...arguments | Array<any> | 否 | 附加参数,一旦定时器到期,它们会作为参数传递给handler。 | + +@@ -26,24 +26,24 @@ setTimeout(handler: Function | string, delay?: number, ...arguments: any[]): num + + | 类型 | 说明 | + | -------- | -------- | +-| number | timeout定时器的ID。 | ++| number | 该定时器的ID。 | + + **示例:** + + ```js +- export default { +- setTimeOut() { +- var timeoutID = setTimeout(function() { +- console.log('delay 1s'); +- }, 1000); +- } +- } ++ setTimeout(function() { ++ console.log('delay 1s'); ++ }, 1000); ++ ++ let timeoutID = setTimeout(function() { ++ console.log('delay 1s'); ++ }, 1000); + ``` + + + ## clearTimeout + +-clearTimeout(timeoutID: number): void ++clearTimeout(timeoutID?: number): void + + 取消了先前通过调用setTimeout()建立的定时器。 + +@@ -53,19 +53,15 @@ clearTimeout(timeoutID: number): void + + | 参数名 | 类型 | 必填 | 说明 | + | -------- | -------- | -------- | -------- | +-| timeoutID | number | 是 | 要取消定时器的ID, 是由setTimeout()返回的。 | ++| timeoutID | number | 否 | 要取消定时器的ID, 是由setTimeout()返回的。如果省略该参数,则不处理。| + + **示例:** + +- ```js +- export default { +- clearTimeOut() { +- var timeoutID = setTimeout(function() { +- console.log('do after 1s delay.'); +- }, 1000); +- clearTimeout(timeoutID); +- } +- } ++ ```js ++ let timeoutID = setTimeout(function() { ++ console.log('do after 1s delay.'); ++ }, 1000); ++ clearTimeout(timeoutID); + ``` + + +@@ -81,32 +77,32 @@ setInterval(handler: Function | string, delay: number, ...arguments: any[]): num + + | 参数名 | 类型 | 必填 | 说明 | + | -------- | -------- | -------- | -------- | +-| handler | Function \| string | 是 | 要重复调用的函数。 | +-| delay | number | 是 | 延迟的毫秒数(一秒等于1000毫秒),函数的调用会在该延迟之后发生。 | ++| handler | Function \| string | 是 | 要重复调用的函数。 类型为string则不处理。| ++| delay | number | 是 | 延迟的毫秒数,函数的调用会在该延迟之后发生。 | + | ...arguments | Array<any> | 否 | 附加参数,一旦定时器到期,他们会作为参数传递给handler。 | + + **返回值:** + + | 类型 | 说明 | + | -------- | -------- | +-| number | intervalID重复定时器的ID。 | ++| number | 该定时器的ID。 | + + **示例:** + + ```js +- export default { +- setInterval() { +- var intervalID = setInterval(function() { +- console.log('do very 1s.'); +- }, 1000); +- } +- } ++ setInterval(function() { ++ console.log('do very 1s.'); ++ }, 1000); ++ ++ let intervalID = setInterval(function() { ++ console.log('do very 1s.'); ++ }, 1000); + ``` + + + ## clearInterval + +-clearInterval(intervalID: number): void ++clearInterval(intervalID?: number): void + + 可取消先前通过setInterval()设置的重复定时任务。 + +@@ -116,17 +112,13 @@ clearInterval(intervalID: number): void + + | 参数名 | 类型 | 必填 | 说明 | + | -------- | -------- | -------- | -------- | +-| intervalID | number | 是 | 要取消的重复定时器的ID,是由 setInterval() 返回的。 | ++| intervalID | number | 否 | 要取消的重复定时器的ID,是由 setInterval() 返回的。如果省略该参数,则不处理。| + + **示例:** + +- ```js +- export default { +- clearInterval() { +- var intervalID = setInterval(function() { +- console.log('do very 1s.'); +- }, 1000); +- clearInterval(intervalID); +- } +- } ++ ```js ++ let intervalID = setInterval(function() { ++ console.log('do very 1s.'); ++ }, 1000); ++ clearInterval(intervalID); + ``` + \ No newline at end of file diff --git a/zh-cn/application-dev/reference/apis/js-apis-logs.md b/zh-cn/application-dev/reference/apis/js-apis-logs.md index 31dd38d142..f907d1d870 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-logs.md +++ b/zh-cn/application-dev/reference/apis/js-apis-logs.md @@ -1,8 +1,6 @@ -# console (日志打印) +# console 控制台 -本模块提供基础的日志打印能力,支持按照日志级别打印日志信息。 - -如果需要使用更高级的日志打印服务,比如按照指定标识筛选日志内容,推荐使用[`@ohos.hilog`](js-apis-hilog.md)。 +本模块提供了一个简单的调试控制台,类似于浏览器提供的JavaScript控制台机制。 > **说明:** > @@ -10,9 +8,9 @@ ## console.debug -debug(message: string): void +debug(message: string, ...arguments: any[]): void -打印debug级别的日志信息。 +以格式化输出方式打印调试信息。 **系统能力:** SystemCapability.ArkUI.ArkUI.Full @@ -21,13 +19,24 @@ debug(message: string): void | 参数名 | 类型 | 必填 | 说明 | | ------- | ------ | ---- | ----------- | | message | string | 是 | 表示要打印的文本信息。 | +| arguments | any | 否 | 表示其余要打印的信息或message的替换值。 | +**示例:** +```js +const number = 5; +console.debug('count: %d', number); // 格式化输出替换message中的文本。 +// count: 5 +console.debug('count:', number); // 打印message以及其余信息 +// count: 5 +console.debug('count:'); // 仅打印message +// count: +``` ## console.log -log(message: string): void +log(message: string, ...arguments: any[]): void -打印debug级别的日志信息。 +以格式化输出方式打印日志信息。用法同console.debug()。 **系统能力:** SystemCapability.ArkUI.ArkUI.Full @@ -36,13 +45,13 @@ log(message: string): void | 参数名 | 类型 | 必填 | 说明 | | ------- | ------ | ---- | ----------- | | message | string | 是 | 表示要打印的文本信息。 | - +| arguments | any | 否 |表示其余要打印的信息或message的替换值。 | ## console.info -info(message: string): void +info(message: string, ...arguments: any[]): void -打印info级别的日志信息。 +以格式化输出方式打印日志信息。(console.log()的别名)。用法同console.debug()。 **系统能力:** SystemCapability.ArkUI.ArkUI.Full @@ -51,13 +60,13 @@ info(message: string): void | 参数名 | 类型 | 必填 | 说明 | | ------- | ------ | ---- | ----------- | | message | string | 是 | 表示要打印的文本信息。 | - +| arguments | any | 否 | 表示其余要打印的信息或message的替换值。 | ## console.warn -warn(message: string): void +warn(message: string, ...arguments: any[]): void -打印warn级别的日志信息。 +以格式化输出方式打印警告信息。用法同console.debug()。 **系统能力:** SystemCapability.ArkUI.ArkUI.Full @@ -66,13 +75,13 @@ warn(message: string): void | 参数名 | 类型 | 必填 | 说明 | | ------- | ------ | ---- | ----------- | | message | string | 是 | 表示要打印的文本信息。 | - +| arguments | any | 否 | 表示其余要打印的信息或message的替换值。 | ## console.error -error(message: string): void +error(message: string, ...arguments: any[]): void -打印error级别的日志信息。 +以格式化输出方式打印错误信息。用法同console.debug()。 **系统能力:** SystemCapability.ArkUI.ArkUI.Full @@ -81,30 +90,15 @@ error(message: string): void | 参数名 | 类型 | 必填 | 说明 | | ------- | ------ | ---- | ----------- | | message | string | 是 | 表示要打印的文本信息。 | +| arguments | any | 否 | 表示其余要打印的信息或message的替换值。 | -**示例:** - -``` -export default { - clickConsole(){ - var versionCode = 1; - console.info('Hello World. The current version code is ' + versionCode); - console.log(`versionCode: ${versionCode}`); - // 以下写法从API Version 6开始支持console.log('versionCode:%d.', versionCode); - } -} -``` - -在DevEco Studio的底部,切换到“HiLog”窗口。选择当前的设备及进程,日志级别选择Info,搜索内容设置为“Hello World”。此时窗口仅显示符合条件的日志,效果如图所示: - -![zh-cn_image_0000001200913929](figures/zh-cn_image_0000001200913929.png) - ## console.assert10+ assert(value?: Object, ...arguments: Object[]): void -若value为假,打印后续内容。 +若value为假(false)或者省略,则console.assert()打印"Assertion failed"这条消息。 +如果 value 为真值(true),则什么也不会发生。 **系统能力:** SystemCapability.Utils.Lang @@ -112,15 +106,16 @@ assert(value?: Object, ...arguments: Object[]): void | 参数名 | 类型 | 必填 | 说明 | | ------- | ------ | ---- | ----------- | -| value | Object | 否 | 值 | +| value | Object | 否 | 语句结果值。省略则打印"Assertion failed"。| | arguments | Object | 否 | 错误消息打印。 | **示例:** -``` +```js console.assert(true, 'does nothing'); +console.assert(2 % 1 == 0, 'does nothing'); // 表达式结果值为true。 console.assert(false, 'console %s work', 'didn\'t'); -// Assertion console:ohos didn't work +// Assertion failed: console didn't work console.assert(); // Assertion failed @@ -129,7 +124,7 @@ console.assert(); count(label?: string): void -维护一个内部计数器, 并输出调用label的console.count()次数。默认值为'default'。 +维护一个内部计数器, 调用时,打印此标签名以及对应的计数次数。 **系统能力:** SystemCapability.Utils.Lang @@ -137,10 +132,11 @@ count(label?: string): void | 参数名 | 类型 | 必填 | 说明 | | ------- | ------ | ---- | ----------- | -| label | string | 否 | 计数器标签名。 | +| label | string | 否 | 计数器标签名。默认值为'default'。| + **示例:** -``` +```js console.count() // default: 1 console.count('default') @@ -150,7 +146,7 @@ console.count('abc') console.count('xyz') // xyz: 1 console.count('abc') -abc: 2 +// abc: 2 console.count() // default: 3 ``` @@ -159,7 +155,7 @@ console.count() countReset(label?: string): void -清除label名的计数。默认值为'default'。 +清除指定标签名的计数。 **系统能力:** SystemCapability.Utils.Lang @@ -167,10 +163,10 @@ countReset(label?: string): void | 参数名 | 类型 | 必填 | 说明 | | ------- | ------ | ---- | ----------- | -| label | string | 否 | 计数器标签名。 | +| label | string | 否 | 计数器标签名。默认值为'default'。| **示例:** -``` +```js console.count('abc'); // abc: 1 console.countReset('abc'); @@ -190,13 +186,24 @@ dir(dir?: Object): void | 参数名 | 类型 | 必填 | 说明 | | ------- | ------ | ---- | ----------- | -| dir | Object | 否 | 需要打印内容的对象。 | +| dir | Object | 否 | 需要打印内容的对象。省略则无任何打印。| + + +**示例:** +```js +let a = { foo: { bar: { baz: true } }}; +console.dir(a); +// Object: {"foo":{"bar":{"baz":true}}} + +console.dir(); // 无打印 +``` + ## console.dirxml10+ dirxml(...arguments: Object[]): void -此方法调用 console.log() 将接收到的参数传给它。此方法不会产生任何 XML 格式。 +此方法调用 console.log() 将接收到的参数传给它。此方法不会产生任何 XML 格式。qi'A使用方法与console.log()一致。 **系统能力:** SystemCapability.Utils.Lang @@ -204,14 +211,14 @@ dirxml(...arguments: Object[]): void | 参数名 | 类型 | 必填 | 说明 | | ------- | ------ | ---- | ----------- | -| arguments | Object | 否 | 要打印的信息。 | +| arguments | Object | 是 | 要打印的信息。 | ## console.group10+ group(...arguments: Object[]): void -将后续行的缩进增加 groupIndentation 长度的空格。 -如果提供需要打印的信息,首先先打印信息,没有额外的缩进。 +默认将后续行的缩进增加两个空格。 +如果提供需要打印的信息,则首先打印信息,没有额外的缩进。 **系统能力:** SystemCapability.Utils.Lang @@ -220,11 +227,26 @@ group(...arguments: Object[]): void | 参数名 | 类型 | 必填 | 说明 | | ------- | ------ | ---- | ----------- | | arguments | Object | 否 | 要打印的信息。 | + +**示例:** +```js +console.log("outter"); +// outter +console.group(); +console.log("level 1"); +// level 1 +console.group("in level1"); +// in level1 +console.log("level 2"); +// level 2 +``` + + ## console.groupCollapsed10+ groupCollapsed(...arguments: Object[]): void -group的别名。 +console.group()的别名。使用方法与console.group()一致。 **系统能力:** SystemCapability.Utils.Lang @@ -238,10 +260,24 @@ group的别名。 groupEnd(): void -将后续行的缩进减少 groupIndentation 长度的空格。 +将后续行的缩进减少两个空格。 **系统能力:** SystemCapability.Utils.Lang + +**示例:** +```js +console.log("outter"); +// outter +console.group(); +console.log("level 1"); +// level 1 +console.groupEnd(); +console.log("outter"); +// outter +``` + + ## console.table10+ table(tableData?: Object): void @@ -254,10 +290,10 @@ table(tableData?: Object): void | 参数名 | 类型 | 必填 | 说明 | | ------- | ------ | ---- | ----------- | -| tableData | Object | 否 | 要打印为表格形式的对象。 | +| tableData | Object | 否 | 要打印为表格形式的对象。省略则无任何打印。 | **示例:** -``` +```js console.table([1, 2, 3]); // ┌─────────┬────────┐ // │ (index) │ Values │ @@ -281,7 +317,7 @@ console.table({ a: [1, 2, 3, 4, 5], b: 5, c: { e: 5 } }); time(label?: string): void -启动可用于计算操作持续时间的计时器。默认值为'default'。可使用console.timeEnd()关闭计时器并打印结果。 +启动可用于计算操作持续时间的计时器。可使用console.timeEnd()关闭计时器并打印结果。 **系统能力:** SystemCapability.Utils.Lang @@ -289,13 +325,13 @@ time(label?: string): void | 参数名 | 类型 | 必填 | 说明 | | ------- | ------ | ---- | ----------- | -| label | string | 否 | 计时器标识。 | +| label | string | 否 | 计时器标识。默认值为'default'。 | ## console.timeEnd10+ timeEnd(label?: string): void -停止之前通过调用 console.time() 启动的计时器并将结果打印。默认值为'default'。 +停止之前通过调用 console.time() 启动的计时器并将结果打印。 **系统能力:** SystemCapability.Utils.Lang @@ -303,10 +339,10 @@ timeEnd(label?: string): void | 参数名 | 类型 | 必填 | 说明 | | ------- | ------ | ---- | ----------- | -| label | string | 否 | 计时器标识。 | +| label | string | 否 | 计时器标识。默认值为'default' | **示例:** -``` +```js console.time('abc'); console.timeEnd('abc'); // abc: 225.438ms @@ -324,14 +360,13 @@ timeLog(label?: string, ...arguments: Object[]): void | 参数名 | 类型 | 必填 | 说明 | | ------- | ------ | ---- | ----------- | -| label | string | 否 | 计时器标识。 | +| label | string | 否 | 计时器标识。默认值为'default' | | arguments | Object | 否 | 需要打印的其他日志。 | **示例:** -``` +```js console.time('timer1'); -const value = aaa(); // 返回 17 -console.timeLog('timer1', value); +console.timeLog('timer1', 17); // timer1: 365.227ms 17 console.timeEnd('timer1'); // timer1: 513.22ms @@ -349,10 +384,14 @@ trace(...arguments: Object[]): void | 参数名 | 类型 | 必填 | 说明 | | ------- | ------ | ---- | ----------- | -| arguments | Object | 否 | 需要打印的其他日志。 | +| arguments | Object | 否 | 需要打印的其他日志。省略则仅打印堆栈信息。| **示例:** -``` +```js console.trace(); +// Trace: + xxxxxxxxxx(当前堆栈信息) console.trace("Show the trace"); +// Trace: Show the trace + xxxxxxxxxx(当前堆栈信息) ``` \ No newline at end of file diff --git a/zh-cn/application-dev/reference/apis/js-apis-timer.md b/zh-cn/application-dev/reference/apis/js-apis-timer.md index ae0957a9b4..669a266234 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-timer.md +++ b/zh-cn/application-dev/reference/apis/js-apis-timer.md @@ -18,7 +18,7 @@ setTimeout(handler: Function | string, delay?: number, ...arguments: any[]): num | 参数名 | 类型 | 必填 | 说明 | | -------- | -------- | -------- | -------- | -| handler | Function \| string | 是 | 定时器到期后执行函数。 | +| handler | Function \| string | 是 | 定时器到期后执行函数。类型为string则打印Error信息,不进行其他处理。 | | delay | number | 否 | 延迟的毫秒数,函数的调用会在该延迟之后发生。如果省略该参数,delay取默认值0,意味着“马上”执行,或尽快执行。 | | ...arguments | Array<any> | 否 | 附加参数,一旦定时器到期,它们会作为参数传递给handler。 | @@ -26,24 +26,20 @@ setTimeout(handler: Function | string, delay?: number, ...arguments: any[]): num | 类型 | 说明 | | -------- | -------- | -| number | timeout定时器的ID。 | +| number | 该定时器的ID。 | **示例:** ```js - export default { - setTimeOut() { - var timeoutID = setTimeout(function() { - console.log('delay 1s'); - }, 1000); - } - } + setTimeout(function() { + console.log('delay 1s'); + }, 1000); ``` ## clearTimeout -clearTimeout(timeoutID: number): void +clearTimeout(timeoutID?: number): void 取消了先前通过调用setTimeout()建立的定时器。 @@ -53,19 +49,15 @@ clearTimeout(timeoutID: number): void | 参数名 | 类型 | 必填 | 说明 | | -------- | -------- | -------- | -------- | -| timeoutID | number | 是 | 要取消定时器的ID, 是由setTimeout()返回的。 | +| timeoutID | number | 否 | 要取消定时器的ID, 是由setTimeout()返回的。如果省略该参数,则不取消任何定时任务,无任何处理。| **示例:** - ```js - export default { - clearTimeOut() { - var timeoutID = setTimeout(function() { - console.log('do after 1s delay.'); - }, 1000); - clearTimeout(timeoutID); - } - } + ```js + let timeoutID = setTimeout(function() { + console.log('do after 1s delay.'); + }, 1000); + clearTimeout(timeoutID); ``` @@ -81,32 +73,28 @@ setInterval(handler: Function | string, delay: number, ...arguments: any[]): num | 参数名 | 类型 | 必填 | 说明 | | -------- | -------- | -------- | -------- | -| handler | Function \| string | 是 | 要重复调用的函数。 | -| delay | number | 是 | 延迟的毫秒数(一秒等于1000毫秒),函数的调用会在该延迟之后发生。 | +| handler | Function \| string | 是 | 要重复调用的函数。类型为string则打印Error信息,不进行其他处理。| +| delay | number | 是 | 延迟的毫秒数,函数的调用会在该延迟之后发生。 | | ...arguments | Array<any> | 否 | 附加参数,一旦定时器到期,他们会作为参数传递给handler。 | **返回值:** | 类型 | 说明 | | -------- | -------- | -| number | intervalID重复定时器的ID。 | +| number | 该定时器的ID。 | **示例:** ```js - export default { - setInterval() { - var intervalID = setInterval(function() { - console.log('do very 1s.'); - }, 1000); - } - } + setInterval(function() { + console.log('do every 1s.'); + }, 1000); ``` ## clearInterval -clearInterval(intervalID: number): void +clearInterval(intervalID?: number): void 可取消先前通过setInterval()设置的重复定时任务。 @@ -116,17 +104,13 @@ clearInterval(intervalID: number): void | 参数名 | 类型 | 必填 | 说明 | | -------- | -------- | -------- | -------- | -| intervalID | number | 是 | 要取消的重复定时器的ID,是由 setInterval() 返回的。 | +| intervalID | number | 否 | 要取消的重复定时器的ID,是由 setInterval() 返回的。如果省略该参数,则不取消任何定时任务,无任何处理。| **示例:** - ```js - export default { - clearInterval() { - var intervalID = setInterval(function() { - console.log('do very 1s.'); - }, 1000); - clearInterval(intervalID); - } - } + ```js + let intervalID = setInterval(function() { + console.log('do every 1s.'); + }, 1000); + clearInterval(intervalID); ``` -- GitLab