Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using underscore.js in node [duplicate]

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?

like image 954
Nullpoet Avatar asked Mar 21 '23 15:03

Nullpoet


1 Answers

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]
like image 159
James Avatar answered Apr 02 '23 18:04

James