Merge pull request #93 from jaredwilli/console-api-updates
updates from issue #13 for console and command line APIs
This commit is contained in:
Коммит
d89a791b17
Двоичный файл не отображается.
После Ширина: | Высота: | Размер: 11 KiB |
Двоичный файл не отображается.
После Ширина: | Высота: | Размер: 15 KiB |
|
@ -87,6 +87,12 @@ Copies a string representation of the specified object to the clipboard.
|
|||
copy($0);
|
||||
|
||||
|
||||
## debug(function)
|
||||
|
||||
When the function specified is called, the debugger will be invoked and will break inside the function on the Sources panel allowing you to be able to step through the code and debug it.
|
||||
|
||||
debug(getData);
|
||||
|
||||
|
||||
## dir(object)
|
||||
|
||||
|
@ -102,14 +108,12 @@ The following example shows the difference between evaluating `document.body` di
|
|||
For more information, see the [`console.dir()`](console-api#consoledirobject) entry in the Console API.
|
||||
|
||||
|
||||
|
||||
## dirxml(object)
|
||||
|
||||
Prints an XML representation of the specified object, as seen in the Elements tab. This method is equivalent to the [`console.dirxml()`](console-api#consoledirxmlobject) method.
|
||||
|
||||
|
||||
|
||||
## inspect(object)
|
||||
## inspect(object/function)
|
||||
|
||||
Opens and selects the specified element or object in the appropriate panel: either the Elements panel for DOM elements and the Profiles panel for JavaScript heap objects.
|
||||
|
||||
|
@ -119,6 +123,7 @@ The following example opens the first child element of `document.body` in the El
|
|||
|
||||
![Inspecting an element with inspect()](commandline-api-files/inspect.png)
|
||||
|
||||
When passing a function to inspect, when the function is called it will open it up in the Sources panel for you to inspect.
|
||||
|
||||
|
||||
## getEventListeners(object) ##
|
||||
|
@ -156,6 +161,18 @@ Assuming `player1` was defined in the global namespace (for simplicity), typing
|
|||
|
||||
|
||||
|
||||
## monitor(function)
|
||||
|
||||
When the function specified is called, a message is logged to the console that indicates the function name along with the arguments that are passed to the function when it was called.
|
||||
|
||||
function sum(x, y) {
|
||||
return x + y;
|
||||
}
|
||||
monitor(sum);
|
||||
|
||||
<img src="commandline-api-files/monitor.png" style="max-width:100%" alt="Example of monitor() method">
|
||||
|
||||
|
||||
## monitorEvents(object[, events])
|
||||
|
||||
When one of the specified events occurs on the specified object, the Event object is logged to the console. You can specify a single event to monitor, an array of events, or one of the generic events "types" that are mapped to a predefined collection of events. See examples below.
|
||||
|
@ -203,6 +220,13 @@ To stop profiling and display the results in the Profiles panel:
|
|||
|
||||
profileEnd("My profile")
|
||||
|
||||
Profiles can also be nested. For example, this will work in any order:
|
||||
|
||||
profile('A');
|
||||
profile('B');
|
||||
profileEnd('A');
|
||||
profileEnd('B');
|
||||
|
||||
For more examples, see [Controlling the CPU profiler](console.md#controlling-the-cpu-profiler).
|
||||
|
||||
|
||||
|
@ -212,6 +236,33 @@ For more examples, see [Controlling the CPU profiler](console.md#controlling-the
|
|||
Stops the current profiling session started with the [profile()](#profilename) method and displays the results in the Profiles panel.
|
||||
|
||||
|
||||
## table(data[, columns])
|
||||
|
||||
Log object data with table by passing in a data object in with optional column headings. For example, to display a list of names using a table in the console you would do:
|
||||
|
||||
var names = {
|
||||
0: { firstName: "John", lastName: "Smith" },
|
||||
1: { firstName: "Jane", lastName: "Doe" }
|
||||
};
|
||||
|
||||
table(names);
|
||||
|
||||
<img src="commandline-api-files/table.png" style="max-width:100%" alt="Example of table() method">
|
||||
|
||||
|
||||
## undebug(function)
|
||||
|
||||
Stops the debugging of the specified function so that when the function is called the debugger will not be invoked, breaking inside the function on the Sources panel.
|
||||
|
||||
undebug(getData);
|
||||
|
||||
|
||||
## unmonitor(function)
|
||||
|
||||
Stops the monitoring of the specified function. For example, the following stops the monitoring of a function named getData():
|
||||
|
||||
unmonitor(getData);
|
||||
|
||||
|
||||
## unmonitorEvents(object[, events])
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@ The Console API provides web applications with methods for writing information t
|
|||
If the specified expression is `false`, the message is written to the console along with a stack trace. In the following example, the assert message is written to the console only when the `document` contains fewer than five child nodes:
|
||||
|
||||
var list = document.querySelector('#myList');
|
||||
console.assert(list.childNodes.length < 10, "List item count is > 10");
|
||||
console.assert(list.childNodes.length < 10, "List item count is >= 10");
|
||||
|
||||
![Example of console.assert()](console-files/assert-failed-list.png)
|
||||
|
||||
|
@ -24,6 +24,8 @@ Clears the console.
|
|||
|
||||
Also see [Clearing the console](console.md#clearing-console-history).
|
||||
|
||||
However, if Preserve Logs is on, console.clear() will not do anything in case there's some iframe which calls console.clear() and can make your debugging process harder. "Clear console" in the context menu will still work, and actually clear the console.
|
||||
|
||||
|
||||
## console.count(label) ##
|
||||
|
||||
|
@ -232,6 +234,16 @@ Stops the timer with the specified label and prints the elapsed time.
|
|||
For example usage, see [console.time()](#consoletimelabel).
|
||||
|
||||
|
||||
## console.timeline(label)
|
||||
|
||||
Starts a Timeline recording with an optional label.
|
||||
|
||||
|
||||
## console.timelineEnd()
|
||||
|
||||
Stops the Timeline recording if one is in progress.
|
||||
|
||||
|
||||
## console.timeStamp([label]) ##
|
||||
|
||||
This method adds an event to the Timeline during a recording session. This lets you visually correlate your code generated time stamp to other events, such as screen layout and paints, that are automatically added to the Timeline.
|
||||
|
@ -239,12 +251,16 @@ This method adds an event to the Timeline during a recording session. This lets
|
|||
See [Marking the Timeline](console.md#marking-the-timeline) for an example of using `console.timeStamp()`.
|
||||
|
||||
|
||||
## console.trace() ##
|
||||
## console.trace(object) ##
|
||||
|
||||
Prints a stack trace from the point where the method was called, including links to the specific lines in the JavaScript source. A counter indicates the number of times that `trace()` method was invoked at that point, as shown in the screen shot below.
|
||||
|
||||
![Example of a stack trace with counter](console-files/console-trace.png)
|
||||
|
||||
It is also possible to pass in arguments to trace(). For example:
|
||||
|
||||
![Example of a stack trace with arguments](console-files/console-trace-args.png)
|
||||
|
||||
|
||||
## console.warn(object [, object, ...]) ##
|
||||
|
||||
|
|
Двоичный файл не отображается.
После Ширина: | Высота: | Размер: 11 KiB |
Загрузка…
Ссылка в новой задаче