节点REPL + Underscore不返回任何方法

时间:2012-11-22 00:59:17

标签: javascript node.js

刚刚开始使用Node.js,并想尝试使用Underscore来测试一些想法。

我阅读了帖子herehere,最后是here

我明白为什么使用_在REPL中不起作用。但是也没有重新分配下划线对象。

例如,

 > var _u = require('underscore');
   { _: 
    { [Function]
      VERSION: '1.0.2',
      forEach: [Function],
      map: [Function],
      reduce: [Function],
      reduceRight: [Function],
      detect: [Function],
      ...feeling good about myself...

 > _u.uniq([1,2,3,4,4,44]);

返回:

TypeError: Object #<Object> has no method 'uniq'
at repl:1:4
at REPLServer.self.eval (repl.js:109:21)
at rli.on.self.bufferedCmd (repl.js:258:20)
at REPLServer.self.eval (repl.js:116:5)
at Interface.<anonymous> (repl.js:248:12)
at Interface.EventEmitter.emit (events.js:96:17)
at Interface._onLine (readline.js:200:10)
at Interface._line (readline.js:518:8)
at Interface._ttyWrite (readline.js:736:14)
at ReadStream.onkeypress (readline.js:97:10)

除了重命名全局下划线对象之外,还有任何关于为什么这不起作用的想法?分配给_u的版本为 1.0.2

1 个答案:

答案 0 :(得分:2)

1.0.2必须相当陈旧。 1.4.2是当前版本。我敢打赌,这个版本的库根本不存在这种方法。

升级时间。