Repository navigation
Expand file tree
/
Copy pathconsole.json
More file actions
490 lines (490 loc) · 17.2 KB
/
Copy pathconsole.json
File metadata and controls
490 lines (490 loc) · 17.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
{
"source": "..\\api\\console.md",
"modules": [
{
"textRaw": "Console",
"name": "console",
"stability": 2,
"stabilityText": "Stable",
"desc": "<p>控制台模块提供了一个和Web浏览器中相似的用于调试的控制台。用于输出一些调试信息、中间结果等。\nconsole模块中的一些函数也可以直接作为全局函数使用,例如log, print等。</p>\n",
"methods": [
{
"textRaw": "console.show()",
"type": "method",
"name": "show",
"desc": "<p>显示控制台。这会显示一个控制台的悬浮窗(需要悬浮窗权限)。</p>\n",
"signatures": [
{
"params": []
}
]
},
{
"textRaw": "console.hide()",
"type": "method",
"name": "hide",
"desc": "<p>隐藏控制台悬浮窗。</p>\n",
"signatures": [
{
"params": []
}
]
},
{
"textRaw": "console.clear()",
"type": "method",
"name": "clear",
"desc": "<p>清空控制台。</p>\n",
"signatures": [
{
"params": []
}
]
},
{
"textRaw": "console.log([data][, ...args])",
"type": "method",
"name": "log",
"signatures": [
{
"params": [
{
"textRaw": "`data` {any} ",
"name": "data",
"type": "any",
"optional": true
},
{
"textRaw": "`...args` {any} ",
"name": "...args",
"type": "any",
"optional": true
}
]
},
{
"params": [
{
"name": "data",
"optional": true
},
{
"name": "...args",
"optional": true
}
]
}
],
"desc": "<p>打印到控制台,并带上换行符。 可以传入多个参数,第一个参数作为主要信息,其他参数作为类似于 <a href=\"http://man7.org/linux/man-pages/man3/printf.3.html\">printf(3)</a> 中的代替值(参数都会传给 util.format())。</p>\n<pre><code>const count = 5;\nconsole.log('count: %d', count);\n// 打印: count: 5 到 stdout\nconsole.log('count:', count);\n// 打印: count: 5 到 stdout\n</code></pre><p>详见 util.format()。</p>\n<p>该函数也可以作为全局函数使用。</p>\n"
},
{
"textRaw": "console.verbose([data][, ...args])",
"type": "method",
"name": "verbose",
"signatures": [
{
"params": [
{
"textRaw": "`data` {any} ",
"name": "data",
"type": "any",
"optional": true
},
{
"textRaw": "`...args` {any} ",
"name": "...args",
"type": "any",
"optional": true
}
]
},
{
"params": [
{
"name": "data",
"optional": true
},
{
"name": "...args",
"optional": true
}
]
}
],
"desc": "<p>与console.log类似,但输出结果以灰色字体显示。输出优先级低于log,用于输出观察性质的信息。</p>\n"
},
{
"textRaw": "console.info([data][, ...args])",
"type": "method",
"name": "info",
"signatures": [
{
"params": [
{
"textRaw": "`data` {any} ",
"name": "data",
"type": "any",
"optional": true
},
{
"textRaw": "`...args` {any} ",
"name": "...args",
"type": "any",
"optional": true
}
]
},
{
"params": [
{
"name": "data",
"optional": true
},
{
"name": "...args",
"optional": true
}
]
}
],
"desc": "<p>与console.log类似,但输出结果以绿色字体显示。输出优先级高于log, 用于输出重要信息。</p>\n"
},
{
"textRaw": "console.warn([data][, ...args])",
"type": "method",
"name": "warn",
"signatures": [
{
"params": [
{
"textRaw": "`data` {any} ",
"name": "data",
"type": "any",
"optional": true
},
{
"textRaw": "`...args` {any} ",
"name": "...args",
"type": "any",
"optional": true
}
]
},
{
"params": [
{
"name": "data",
"optional": true
},
{
"name": "...args",
"optional": true
}
]
}
],
"desc": "<p>与console.log类似,但输出结果以蓝色字体显示。输出优先级高于info, 用于输出警告信息。</p>\n"
},
{
"textRaw": "console.error([data][, ...args])",
"type": "method",
"name": "error",
"signatures": [
{
"params": [
{
"textRaw": "`data` {any} ",
"name": "data",
"type": "any",
"optional": true
},
{
"textRaw": "`...args` {any} ",
"name": "...args",
"type": "any",
"optional": true
}
]
},
{
"params": [
{
"name": "data",
"optional": true
},
{
"name": "...args",
"optional": true
}
]
}
],
"desc": "<p>与console.log类似,但输出结果以红色字体显示。输出优先级高于warn, 用于输出错误信息。</p>\n"
},
{
"textRaw": "console.assert(value, message)",
"type": "method",
"name": "assert",
"signatures": [
{
"params": [
{
"textRaw": "value {any} 要断言的布尔值 ",
"name": "value",
"type": "any",
"desc": "要断言的布尔值"
},
{
"textRaw": "message {string} value为false时要输出的信息 ",
"name": "message",
"type": "string",
"desc": "value为false时要输出的信息"
}
]
},
{
"params": [
{
"name": "value"
},
{
"name": "message"
}
]
}
],
"desc": "<p>断言。如果value为false则输出错误信息message并停止脚本运行。</p>\n<pre><code>var a = 1 + 1;\nconsole.assert(a == 2, "加法出错啦");\n</code></pre>"
},
{
"textRaw": "console.time([label])",
"type": "method",
"name": "time",
"desc": "<p><strong>[v4.1.0新增]</strong></p>\n<ul>\n<li><code>label</code> {String} 计时器标签,可省略</li>\n</ul>\n<p>启动一个定时器,用以计算一个操作的持续时间。\n定时器由一个唯一的 <code>label</code> 标识。\n当调用 <code>console.timeEnd()</code> 时,可以使用相同的 <code>label</code> 来停止定时器,并以毫秒为单位将持续时间输出到控制台。\n重复启动同一个标签的定时器会覆盖之前启动同一标签的定时器。</p>\n",
"signatures": [
{
"params": [
{
"name": "label",
"optional": true
}
]
}
]
},
{
"textRaw": "console.timeEnd(label)",
"type": "method",
"name": "timeEnd",
"desc": "<p><strong>[v4.1.0新增]</strong></p>\n<ul>\n<li><code>label</code> {String} 计时器标签</li>\n</ul>\n<p>停止之前通过调用 <code>console.time()</code> 启动的定时器,并打印结果到控制台。\n调用 <code>console.timeEnd()</code> 后定时器会被删除。如果不存在标签指定的定时器则会打印 <code>NaNms</code>。</p>\n<pre><code class=\"lang-js\">console.time('求和');\nvar sum = 0;\nfor(let i = 0; i < 100000; i++){\n sum += i;\n}\nconsole.timeEnd('求和');\n// 打印 求和: xxx ms\n</code></pre>\n",
"signatures": [
{
"params": [
{
"name": "label"
}
]
}
]
},
{
"textRaw": "console.trace([data][, ...args])",
"type": "method",
"name": "trace",
"desc": "<p><strong>[v4.1.0新增]</strong></p>\n<ul>\n<li><code>data</code> {any}</li>\n<li><code>...args</code> {any}</li>\n</ul>\n<p>与console.log类似,同时会打印出调用这个函数所在的调用栈信息(即当前运行的文件、行数等信息)。</p>\n<pre><code class=\"lang-js\">console.trace('Show me');\n// 打印: (堆栈跟踪会根据被调用的跟踪的位置而变化)\n// Show me\n// at <test>:7\n</code></pre>\n",
"signatures": [
{
"params": [
{
"name": "data",
"optional": true
},
{
"name": "...args",
"optional": true
}
]
}
]
},
{
"textRaw": "console.input(data[, ...args])",
"type": "method",
"name": "input",
"signatures": [
{
"params": [
{
"textRaw": "`data` {any} ",
"name": "data",
"type": "any"
},
{
"textRaw": "`...args` {any} ",
"name": "...args",
"type": "any",
"optional": true
}
]
},
{
"params": [
{
"name": "data"
},
{
"name": "...args",
"optional": true
}
]
}
],
"desc": "<p>与console.log一样输出信息,并在控制台显示输入框等待输入。按控制台的确认按钮后会将输入的字符串用eval计算后返回。</p>\n<p><strong>部分机型可能会有控制台不显示输入框的情况,属于bug。</strong></p>\n<p>例如:</p>\n<pre><code>var n = console.input("请输入一个数字:"); \n//输入123之后:\ntoast(n + 1);\n//显示124\n</code></pre>"
},
{
"textRaw": "console.rawInput(data[, ...args])",
"type": "method",
"name": "rawInput",
"signatures": [
{
"params": [
{
"textRaw": "`data` {any} ",
"name": "data",
"type": "any"
},
{
"textRaw": "`...args` {any} ",
"name": "...args",
"type": "any",
"optional": true
}
]
},
{
"params": [
{
"name": "data"
},
{
"name": "...args",
"optional": true
}
]
}
],
"desc": "<p>与console.log一样输出信息,并在控制台显示输入框等待输入。按控制台的确认按钮后会将输入的字符串直接返回。</p>\n<p>部分机型可能会有控制台不显示输入框的情况,属于bug。</p>\n<p>例如:</p>\n<pre><code>var n = console.rawInput("请输入一个数字:"); \n//输入123之后:\ntoast(n + 1);\n//显示1231\n</code></pre>"
},
{
"textRaw": "console.setSize(w, h)",
"type": "method",
"name": "setSize",
"signatures": [
{
"params": [
{
"textRaw": "`w` {number} 宽度 ",
"name": "w",
"type": "number",
"desc": "宽度"
},
{
"textRaw": "`h` {number} 高度 ",
"name": "h",
"type": "number",
"desc": "高度"
}
]
},
{
"params": [
{
"name": "w"
},
{
"name": "h"
}
]
}
],
"desc": "<p>设置控制台的大小,单位像素。</p>\n<pre><code>console.show();\n//设置控制台大小为屏幕的四分之一\nconsole.setSize(device.width / 2, device.height / 2);\n</code></pre>"
},
{
"textRaw": "console.setPosition(x, y)",
"type": "method",
"name": "setPosition",
"signatures": [
{
"params": [
{
"textRaw": "`x` {number} 横坐标 ",
"name": "x",
"type": "number",
"desc": "横坐标"
},
{
"textRaw": "`y` {number} 纵坐标 ",
"name": "y",
"type": "number",
"desc": "纵坐标"
}
]
},
{
"params": [
{
"name": "x"
},
{
"name": "y"
}
]
}
],
"desc": "<p>设置控制台的位置,单位像素。</p>\n<pre><code>console.show();\nconsole.setPosition(100, 100);\n</code></pre>"
},
{
"textRaw": "console.setGlobalLogConfig(config)",
"type": "method",
"name": "setGlobalLogConfig",
"desc": "<p><strong>[v4.1.0新增]</strong></p>\n<ul>\n<li><code>config</code> {Object} 日志配置,可选的项有:<ul>\n<li><code>file</code> {string} 日志文件路径,将会把日志写入该文件中</li>\n<li><code>maxFileSize</code> {number} 最大文件大小,单位字节,默认为512 * 1024 (512KB)</li>\n<li><code>rootLevel</code> {string} 写入的日志级别,默认为"ALL"(所有日志),可以为"OFF"(关闭), "DEBUG", "INFO", "WARN", "ERROR", "FATAL"等。</li>\n<li><code>maxBackupSize</code> {number} 日志备份文件最大数量,默认为5</li>\n<li><code>filePattern</code> {string} 日志写入格式,参见<a href=\"http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/PatternLayout.html\">PatternLayout</a></li>\n</ul>\n</li>\n</ul>\n<p>设置日志保存的路径和配置。例如把日志保存到"/sdcard/1.txt":</p>\n<pre><code>console.setGlobalLogConfig({\n "file": "/sdcard/1.txt"\n});\n</code></pre><p>注意该函数会影响所有脚本的日志记录。</p>\n",
"signatures": [
{
"params": [
{
"name": "config"
}
]
}
]
},
{
"textRaw": "print(text)",
"type": "method",
"name": "print",
"signatures": [
{
"params": [
{
"textRaw": "text {string} | {Object} 要打印到控制台的信息 ",
"name": "text",
"type": "string",
"desc": "| {Object} 要打印到控制台的信息"
}
]
},
{
"params": [
{
"name": "text"
}
]
}
],
"desc": "<p>相当于<code>log(text)</code>。</p>\n"
}
],
"type": "module",
"displayName": "Console"
}
]
}