Displaying [Function]'s in the REPL #3509

Closed
wavded opened this Issue Jun 22, 2012 · 3 comments

Projects

None yet

3 participants

@wavded
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
[Function]

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.

@Southern

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' };
console.log(test.toString());
// => [object Object]

var inspect = require('util').inspect;
console.log(inspect(test));
// => { test: 'test', test2: 'test2' }
@wavded
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
fe0fd02
@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
3173d2f
@chrisdickinson

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