joyent/node — pull request #3804 by viatropos (2012-07-31 20:46:55+00:00)
Title: Ability to specify "last result variable name" for REPL (instead of hardcoding `_`)

What are your thoughts about being able to tell the `node` command/REPL to use a different value other than `_` to hold the last result?

The main reason is, if you want to use the `underscore.js` module in the context of the REPL, you essentially have to do one of the following:

#### 1. Declare it at the top of each file

``` javascript
var _ = require('underscore');

// code
```

An issue with this is you can't access the last return value from anywhere in that script. I don't know why you would want to, but there's a limitation there. Also, this means you have to declare `var _ = require('underscore')` in every module, which is only "required" for the underscore module since it conflicts with the explicitly set `_` in the REPL.

#### 2. Declare it every time you use it

``` javascript
var a = function() {
var _ = require('underscore');
// code
}
var b = function() {
var _ = require('underscore');
// code
}
```

I would like to be able to set the underscore module to a global variable, `global._ = require('underscore');`, since it is used so much and is basically a standard js core-extension library. But if it's set to a global variable, the first time there is a return value (in an async function, see https://gist.github.com/gists/3220108), the `_` variable which was the underscore module gets replaced with the last return value.

If you could run the `node` command with a flag specifying the "last result variable name", that would be pretty awesome:

```
node --last-result $_
> "a string"
"a string"
> $_
"a string"
> _
undefined
```

What are your thoughts about this?