Using underscore.js in node

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

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

Why do keys function due to failure? Did I miss something?

+4
source share
1 answer

_It uses the Node the REPL , to store the result of the last expression, so after your initial call will refer to a function . To avoid this, you need to explicitly use a non-conflict name as a reference to the underscore, for example._.keys _keys

$node
> _und = require('./underscore.js')
...
> _und.keys
[Function: keys]
> _und.keys
[Function: keys]
+7
source

All Articles