[ACCEPTED]-Using the Underscore module with Node.js-underscore.js
As of today (April 30, 2012) you can use Underscore as usual 6 on your Node.js code. Previous comments 5 are right pointing that REPL interface (Node's 4 command line mode) uses the "_" to hold 3 the last result BUT on you are free to use 2 it on your code files and it will work without 1 a problem by doing the standard:
var _ = require('underscore');
Happy coding!
The Node REPL uses the underscore variable 4 to hold the result of the last operation, so 3 it conflicts with the Underscore library's 2 use of the same variable. Try something 1 like this:
Admin-MacBook-Pro:test admin$ node
> _und = require("./underscore-min")
{ [Function]
_: [Circular],
VERSION: '1.1.4',
forEach: [Function],
each: [Function],
map: [Function],
inject: [Function],
(...more functions...)
templateSettings: { evaluate: /<%([\s\S]+?)%>/g, interpolate: /<%=([\s\S]+?)%>/g },
template: [Function] }
> _und.max([1,2,3])
3
> _und.max([4,5,6])
6
Or :
var _ = require('underscore')._;
0
The name _
used by the node.js
REPL to hold the 1 previous input. Choose another name.
More Related questions
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.