为什么lodash _.without()会改变_的值?

时间:2014-04-01 03:55:33

标签: javascript lodash

我只是在节点repl中尝试lodash。

首先我要求lodash

_ = require('lodash')

然后我尝试其中一个功能

_.without([1,2,3], 1)
[ 2, 3 ]

但是,如果我再次运行

> _.without([1,2,3], 1)
TypeError: Object 2,3 has no method 'without'
    at repl:1:4
    at REPLServer.self.eval (repl.js:110:21)
    at Interface.<anonymous> (repl.js:239:12)
    at Interface.EventEmitter.emit (events.js:95:17)
    at Interface._onLine (readline.js:202:10)
    at Interface._line (readline.js:531:8)
    at Interface._ttyWrite (readline.js:760:14)
    at ReadStream.onkeypress (readline.js:99:10)
    at ReadStream.EventEmitter.emit (events.js:98:17)
    at emitKey (readline.js:1095:12)

现在_(lodash lib)是一个数组?

1 个答案:

答案 0 :(得分:3)

因为在nodejs中,REPL _是最后一个表达式的结果。你不应该在nodejs REPL中使用_作为任何东西。

http://nodejs.org/api/repl.html