4

I am trying to use keys function from underscore in node console as follows

$node
> require('./underscore.js')
...
> _.keys
[Function: keys]
> _.keys
undefined

Why does keys function disapper? Am I missing something here?

Nullpoet
  • 10,949
  • 20
  • 48
  • 65

1 Answers1

7

The _ is used by Node REPL to store the result of the last expression therefore after your initial call to _.keys the _ will be referencing the keys function. To avoid this you need to explicitly use a non-clashing name as a reference to underscore e.g.

$node
> _und = require('./underscore.js')
...
> _und.keys
[Function: keys]
> _und.keys
[Function: keys]
Uli Köhler
  • 13,012
  • 16
  • 70
  • 120
James
  • 80,725
  • 18
  • 167
  • 237