Using the Underscore module with Node.js

后端 未结 5 1489
悲&欢浪女
悲&欢浪女 2020-11-28 02:17

I\'ve been learning about node.js and modules, and can\'t seem to get the Underscore library to work properly... it seems that the first time I use a function from Underscor

5条回答
  •  萌比男神i
    2020-11-28 03:03

    The Node REPL uses the underscore variable to hold the result of the last operation, so it conflicts with the Underscore library's use of the same variable. Try something 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
    

提交回复
热议问题