[ACCEPTED]-Using the Underscore module with Node.js-underscore.js

Accepted answer
Score: 196

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!

Score: 171

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
Score: 29

Or :

    var _ = require('underscore')._;

0

Score: 13

The name _ used by the node.js REPL to hold the 1 previous input. Choose another name.

More Related questions