|
1 |
| -* log |
2 |
| -* debug |
3 |
| -* error |
4 |
| -* warn |
5 |
| -* trace |
6 |
| -* time |
7 |
| -* timeEnd |
8 |
| -* assert |
9 |
| -* clear |
10 |
| -* dir |
11 |
| -* dirxml |
12 |
| -* trace |
13 |
| -* group |
14 |
| -* groupCollapsed |
15 |
| -* groupEnd |
16 |
| -* timeStamp |
17 |
| -* profile |
18 |
| -* profileend |
19 |
| -* count |
20 |
| -* exception |
21 |
| -* table |
22 |
| -* info |
23 |
| -* msIsIndependentlyComposed |
| 1 | +------------------- |
| 2 | +methods |
| 3 | + |
| 4 | +console.assert(expression, object) |
| 5 | +===== |
| 6 | +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: |
| 7 | +```javascript |
| 8 | +var list = document.querySelector('#myList'); |
| 9 | +console.assert(list.childNodes.length < 10, "List item count is > 10"); |
| 10 | +``` |
| 11 | + |
| 12 | +console.clear() |
| 13 | +===== |
| 14 | +Clears the console. |
| 15 | +```javascript |
| 16 | +console.clear(); |
| 17 | +``` |
| 18 | + |
| 19 | + |
| 20 | +console.count(label) |
| 21 | +===== |
| 22 | +Writes the the number of times that count() has been invoked at the same line and with the same label. |
| 23 | + |
| 24 | +In the following example count() is invoked each time the login() function is invoked. |
| 25 | +```javascript |
| 26 | +function login(user) { |
| 27 | + console.count("Login called"); |
| 28 | + // login() code... |
| 29 | +} |
| 30 | +``` |
| 31 | + |
| 32 | +console.debug(object [,object, ...]) |
| 33 | +===== |
| 34 | +This method is an alias for to `console.log()`. |
| 35 | + |
| 36 | + |
| 37 | +console.dir(object) |
| 38 | +===== |
| 39 | +Prints a JavaScript representation of the specified object. If the object being logged is an HTML element, then the properties of its DOM representation are displayed, as shown below: |
| 40 | +```javascript |
| 41 | +console.dir(document.body); |
| 42 | +``` |
| 43 | + |
| 44 | +You can also use the object formatter (%O) in a `console.log()` statement to print out an element's JavaScript properties: |
| 45 | + |
| 46 | +```javascript |
| 47 | +console.log("document body: %O", document.body); |
| 48 | +``` |
| 49 | + |
| 50 | +Calling console.dir() on a JavaScript object is equivalent to calling `console.log()` on the same object—they both print out the object's JavaScript properites in a tree format. |
| 51 | + |
| 52 | + |
| 53 | +console.dirxml(object) |
| 54 | +===== |
| 55 | +Prints an XML representation of the specified object, as it would appear in the Elements panel. For HTML elements, calling this method is equivalent to calling `console.log()`. |
| 56 | + |
| 57 | +```javascript |
| 58 | +var list = document.querySelector("#myList"); |
| 59 | +console.dirxml(); |
| 60 | +%O is a shortcut for dir %o acts either as dir or dirxml depending on the object type (non-dom or dom) |
| 61 | +``` |
| 62 | + |
| 63 | +console.error(object [, object, ...]) |
| 64 | +===== |
| 65 | +Similar to `console.log()`, `console.error()` and also includes a stack trace from where the method was called. |
| 66 | + |
| 67 | +```javascript |
| 68 | +function connectToServer() { |
| 69 | + var errorCode = 1; |
| 70 | + if (errorCode) { |
| 71 | + console.error("Error: %s (%i)", "Server is not responding", 500); |
| 72 | + } |
| 73 | +} |
| 74 | +connectToServer(); |
| 75 | +``` |
| 76 | + |
| 77 | + |
| 78 | +console.exception(error-object[, object, ...]) |
| 79 | +==== |
| 80 | +Prints an error message and stack trace of JavaScript execution (This exists in firebug, I think it is essentially `console.error`). |
| 81 | + |
| 82 | + |
| 83 | + |
| 84 | +console.group(object[, object, ...]) |
| 85 | +===== |
| 86 | +Starts a new logging group with an optional title. All console output that occurs after calling this method and calling `console.groupEnd() `appears in the same visual group. |
| 87 | + |
| 88 | +```javascript |
| 89 | +console.group("Authenticating user '%s'", user); |
| 90 | +console.log("User authenticated"); |
| 91 | +console.groupEnd(); |
| 92 | +``` |
| 93 | + |
| 94 | +You can also nest groups: |
| 95 | + |
| 96 | +```javascript |
| 97 | +// New group for authentication: |
| 98 | +console.group("Authenticating user '%s'", user); |
| 99 | +// later... |
| 100 | +console.log("User authenticated", user); |
| 101 | +// A nested group for authorization: |
| 102 | +console.group("Authorizing user '%s'", user); |
| 103 | +console.log("User authorized"); |
| 104 | +console.groupEnd(); |
| 105 | +console.groupEnd(); |
| 106 | +``` |
| 107 | + |
| 108 | +console.groupCollapsed(object[, object, ...]) |
| 109 | +===== |
| 110 | +Creates a new logging group that is initially collapsed instead of open, as with `console.group()`. |
| 111 | + |
| 112 | +```javascript |
| 113 | +console.groupCollapsed("Authenticating user '%s'", user); |
| 114 | +console.log("User authenticated"); |
| 115 | +console.groupEnd(); |
| 116 | +console.log("A group-less log trace."); |
| 117 | +``` |
| 118 | + |
| 119 | + |
| 120 | +console.groupEnd() |
| 121 | +===== |
| 122 | +Closes the most recently created logging group that previously created with `console.group()` or `console.groupCollapsed()`. See console.group() and console.groupCollapsed() for examples. |
| 123 | + |
| 124 | + |
| 125 | +console.info(object [, object, ...]) |
| 126 | +===== |
| 127 | +This method is identical to console.log() |
| 128 | + |
| 129 | + |
| 130 | +console.isIndependentlyComposed |
| 131 | +==== |
| 132 | +Todo... describe this. |
| 133 | + |
| 134 | + |
| 135 | +console.log(object [, object, ...]) |
| 136 | +==== |
| 137 | +Displays a message in the console. You pass one or more objects to this method, each of which are evaluated and concatenated into a space-delimited string. The first parameter you pass to log() may contain format specifiers, a string token composed of the percent sign (%) followed by a letter that indicates the formatting to be applied. |
| 138 | + |
| 139 | + |
| 140 | +console.profile([label]) |
| 141 | +==== |
| 142 | +Calling this function initiates a JavaScript CPU profile with an optional label. To complete the profile, call console.profileEnd(). |
| 143 | + |
| 144 | +Each profile you create with this method is added to the console.profiles[] array. Each member of the array is an object for the profile that can be stringified, useful in continuous integration/remote debugging setups. |
| 145 | + |
| 146 | +In the following example a CPU profile is started at the entry to a function that is suspected to consume excessive CPU resources, and ended when the function exits. |
| 147 | +```javascript |
| 148 | +function processPixels() { |
| 149 | + console.profile("Processing pixels"); |
| 150 | + // later, after processing pixels |
| 151 | + console.profileEnd(); |
| 152 | +} |
| 153 | +``` |
| 154 | + |
| 155 | +console.profileEnd() |
| 156 | +==== |
| 157 | +Stops the current JavaScript CPU profiling session, if one is in progress, and prints the report to the Profiles panel. |
| 158 | +```javascript |
| 159 | +console.profileEnd() |
| 160 | +``` |
| 161 | + |
| 162 | + |
| 163 | +console.table(data[, columns]) |
| 164 | +==== |
| 165 | +Allows to log provided data using tabular layout. `data` can be an array of arrays or list of objects), the optional second (array) parameter can be used to filter specific particular columns/properties to be logged. |
| 166 | + |
| 167 | + |
| 168 | +console.time(label) |
| 169 | +==== |
| 170 | +Starts a new timer with an associated label. When console.timeEnd() is called with the same label, the timer is stopped the elapsed time displayed in the Console. Timer values are accurate to the sub-millisecond. |
| 171 | +```javascript |
| 172 | +console.time("Array initialize"); |
| 173 | +var array= new Array(1000000); |
| 174 | +for (var i = array.length - 1; i >= 0; i--) { |
| 175 | + array[i] = new Object(); |
| 176 | +}; |
| 177 | +console.timeEnd("Array initialize"); |
| 178 | +``` |
| 179 | + |
| 180 | +console.timeEnd(label) |
| 181 | +==== |
| 182 | +Stops the timer with the specified label and prints the elapsed time. |
| 183 | + |
| 184 | +For example usage, see `console.time()`. |
| 185 | + |
| 186 | + |
| 187 | +console.timeStamp([label]) |
| 188 | +==== |
| 189 | +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. |
| 190 | + |
| 191 | +See Marking the Timeline for an example of using `console.timeStamp()`. |
| 192 | + |
| 193 | +console.trace() |
| 194 | +=== |
| 195 | +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 `console.trace()` method was invoked at that point. |
| 196 | + |
| 197 | +console.warn(object [, object, ...]) |
| 198 | +==== |
| 199 | +This method is like `console.log()` but also displays a yellow warning icon along with the logged message. |
| 200 | +```javascript |
| 201 | +console.warn("User limit reached! (%d)", userPoints); |
| 202 | +``` |
| 203 | + |
| 204 | + |
| 205 | +------------ |
| 206 | +Properties |
| 207 | + |
| 208 | +console.profiles |
| 209 | +==== |
| 210 | + |
| 211 | + |
| 212 | + |
0 commit comments