You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In the repl documentation it mentions that the _ variable is special and always refers to the result of the last expression. In other words, you cannot use _ in the repl for your own use, as it will get overwritten every time you execute a "line" of code.
the use of _ is so common for lodash or underscore. I don't have any reason why _ is chosen to be the default result. . would be far more acceptable than _
Why not just disable _ functionality with a warning once it's being assigned to? Not being able to paste lodash examples in the REPL is not ideal, imho.
I suggest to add an entry in help command like below
node 🙈 ₹ node
> .help
break Sometimes you get stuck, this gets you out
clear Alias for .break
exit Exit the repl
help Show repl options
load Load JS from a file into the REPL session
save Save all evaluated commands in this REPL session to a file
_ Bound to last successfully evaluated expression
>
Activity
mscdex commentedon Feb 25, 2016
In the
repldocumentation it mentions that the_variable is special and always refers to the result of the last expression. In other words, you cannot use_in the repl for your own use, as it will get overwritten every time you execute a "line" of code.calidion commentedon Feb 25, 2016
the use of
_is so common for lodash or underscore. I don't have any reason why_is chosen to be the default result..would be far more acceptable than_vkurchatkin commentedon Feb 25, 2016
. is not a valid identifier
rvagg commentedon Feb 25, 2016
Just out of interest I thought I've do some provenance work on this
_was introduced in repl.js back in the 25th of September 2009 @ 7674bd5Underscore was born almost exactly one month later, on the 26th of October 2009 @ jashkenas/underscore@02ede85
Perhaps we should go argue to Underscore and lodash that they should change to something that won't conflict with Node?
vkurchatkin commentedon Feb 25, 2016
FWIW Chrome console uses
$_for this and it works the same waybnoordhuis commentedon Feb 25, 2016
To add to what @rvagg said, the underscore's behavior was copied from the python and ruby REPLs.
calidion commentedon Feb 25, 2016
I think
__or__lastor__xxxwould be much acceptable where__is known to be system reserved.bnoordhuis commentedon Feb 25, 2016
It's been
_for over half a decade now, it's not going to change.vkurchatkin commentedon Feb 25, 2016
We could try two things:
_;_is defined;calidion commentedon Feb 25, 2016
@vkurchatkin
I would say that is a very good idea.
💯
rvagg commentedon Feb 25, 2016
I like that suggestion @vkurchatkin, would lead to fewer surprises like the one that prompted this issue
silverwind commentedon Feb 25, 2016
Why not just disable
_functionality with a warning once it's being assigned to? Not being able to paste lodash examples in the REPL is not ideal, imho.[-]strange bug[/-][+]assigning _ in the repl has side effects[/+]princejwesley commentedon Feb 25, 2016
I suggest to add an entry in
helpcommand like belowrvagg commentedon Feb 26, 2016
see #5438 for one option
repl: Assignment of _ allowed with warning