Displaying [Function]'s in the REPL #3509

wavded opened this Issue Jun 22, 2012 · 3 comments


None yet

3 participants

wavded commented Jun 22, 2012

This is stolen from MongoDB's REPL but it would be nice to print the function contents of a function when referencing it directly... e.g.

> console.log

Could be much more informative, like:

> console.log
function () {
  process.stdout.write(util.format.apply(this, arguments) + '\n');

Right now one way you can achieve this is by doing:

> console.log(console.log.toString())

Why not just make that default display? Thoughts? IMO makes the REPL an even more helpful teaching and debugging tool.


There's only one thing that I see wrong with this. Using .toString() wouldn't work with everything. For example, Objects.

var test = { test: 'test', test2: 'test2' };
// => [object Object]

var inspect = require('util').inspect;
// => { test: 'test', test2: 'test2' }
wavded commented Jun 22, 2012

@Southern agreed, I wouldn't use it for anything but [Function] types

@Southern Southern added a commit to Southern/node that referenced this issue Jun 28, 2012
@Southern Southern Automatically `.toString()` functions in REPL.
Fixes #3509
@isaacs isaacs added a commit to isaacs/node-v0.x-archive that referenced this issue Jul 14, 2012
@Southern @isaacs Southern + isaacs Automatically `.toString()` functions in REPL.
Fixes #3509

Without more work, large functions (or functions embedded in objects) would be very noisy in REPL output; in any case, it's easy to enable this behavior on a once-off basis:

console.log + ''

Alternatively, to enable it for an entire REPL session:

Function.prototype.inspect = Function.prototype.toString
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment