jch*_*hes 14 require include node.js underscore.js
当我在控制台中运行节点并键入时var _ = require('underscore');,_最终未定义.如果我将相同的代码放在一个文件中并执行它,那么下划线库将按预期包含在内.
$ 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],
...
>
Run Code Online (Sandbox Code Playgroud)
但是执行的.js文件中的相同代码node test.js显示两个库按预期加载.这是怎么回事?
Dan*_* D. 31
Node repl绑定_到最后一个评估输入的值; 它会覆盖你的_绑定var _ = ...;.另请参阅repl上的node.js文档.
无论替换什么都是如此...,例如:
$ node
> var _ = "any value";
undefined
> _
undefined
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2903 次 |
| 最近记录: |