Commit 7606bdb
util: display constructor when inspecting objects
This commit modifies util.inspect(obj) to additionally show the name of
the function that constructed the object. This often reveals useful
information about the object's prototype. In other words, instead of
> new Cls
{}
we have
> new Cls
Cls {}
This also works with exotic objects:
> class ArrayCls extends Array {}
> new ArrayCls(1, 2, 3)
ArrayCls [ 1, 2, 3 ]
The names of "trivial" constructors like Object and Array are not shown,
unless there is a mismatch between the object representation and the
prototype:
> Object.create([])
Array {}
This feature is inspired by browser devtools.
PR-URL: #1935
Reviewed-By: Roman Reiss <me@silverwind.io>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>1 parent 94b765f commit 7606bdbCopy full SHA for 7606bdb
File tree
Expand file treeCollapse file tree
3 files changed
+71
-5
lines changedOpen diff view settings
Filter options
- lib
- test/parallel
Expand file treeCollapse file tree
3 files changed
+71
-5
lines changedOpen diff view settings
Collapse file
+28-3Lines changed: 28 additions & 3 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
167 | 167 | |
168 | 168 | |
169 | 169 | |
| 170 | + |
| 171 | + |
| 172 | + |
| 173 | + |
| 174 | + |
| 175 | + |
| 176 | + |
| 177 | + |
| 178 | + |
| 179 | + |
| 180 | + |
| 181 | + |
| 182 | + |
| 183 | + |
| 184 | + |
| 185 | + |
170 | 186 | |
171 | 187 | |
172 | 188 | |
| ||
260 | 276 | |
261 | 277 | |
262 | 278 | |
| 279 | + |
263 | 280 | |
264 | 281 | |
265 | 282 | |
| 283 | + |
| 284 | + |
266 | 285 | |
267 | 286 | |
268 | 287 | |
269 | 288 | |
270 | | - |
| 289 | + |
271 | 290 | |
272 | 291 | |
273 | 292 | |
| ||
276 | 295 | |
277 | 296 | |
278 | 297 | |
279 | | - |
| 298 | + |
280 | 299 | |
281 | 300 | |
282 | 301 | |
| ||
286 | 305 | |
287 | 306 | |
288 | 307 | |
289 | | - |
| 308 | + |
290 | 309 | |
291 | 310 | |
| 311 | + |
| 312 | + |
292 | 313 | |
293 | 314 | |
294 | 315 | |
| ||
336 | 357 | |
337 | 358 | |
338 | 359 | |
| 360 | + |
| 361 | + |
| 362 | + |
| 363 | + |
339 | 364 | |
340 | 365 | |
341 | 366 | |
|
Collapse file
+1-1Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
17 | 17 | |
18 | 18 | |
19 | 19 | |
20 | | - |
| 20 | + |
21 | 21 | |
22 | 22 | |
23 | 23 | |
|
Collapse file
test/parallel/test-util-inspect.js
Copy file name to clipboardExpand all lines: test/parallel/test-util-inspect.js+42-1Lines changed: 42 additions & 1 deletion
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
61 | 61 | |
62 | 62 | |
63 | 63 | |
64 | | - |
| 64 | + |
65 | 65 | |
66 | 66 | |
67 | 67 | |
| ||
306 | 306 | |
307 | 307 | |
308 | 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 | + |
0 commit comments