Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
为什么在node.js REPL上执行require(';下划线';)时返回undefined?_Node.js_Include_Require_Underscore.js - Fatal编程技术网

为什么在node.js REPL上执行require(';下划线';)时返回undefined?

为什么在node.js REPL上执行require(';下划线';)时返回undefined?,node.js,include,require,underscore.js,Node.js,Include,Require,Underscore.js,当我在控制台中运行node并键入var\uz=require('下划线'),最终未定义。如果我将相同的代码放在一个文件中并执行它,下划线库将按预期包含 $ node > var _ = require('underscore'); > console.log(_) undefined // underscore library does not load > var async = require('async'); undefined > console.log(asy

当我在控制台中运行node并键入
var\uz=require('下划线')
最终未定义。如果我将相同的代码放在一个文件中并执行它,下划线库将按预期包含

$ node
> var _ = require('underscore');
> console.log(_)
undefined // underscore library does not load
> var async = require('async');
undefined
> console.log(async) // async library does
{ noConflict: [Function],
  nextTick: [Function],
  forEach: [Function],
...
>

但是作为
node test.js
执行的.js文件中的相同代码显示了两个库按预期加载。发生了什么事?

节点repl将
\uu
绑定到上一次计算输入的值;它覆盖了
var中的
\
绑定。另见

无论是什么替代了
,例如:

$ node
> var _ = "any value";
undefined
> _
undefined

这让我快发疯了!这也快把我逼疯了。我想指出,这个答案适用于lodash和下划线。