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,299
  • 16
  • 47
  • 62

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
  • 12,474
  • 14
  • 64
  • 110
James
  • 77,877
  • 18
  • 158
  • 228