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?

0

1 Answer 1

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]
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.