2011-11-22 166 views
1

问题:我刚刚开始使用node.js,并且在使用REPL至require模块时,其函数始终显示未定义。它出了什么问题?REPL中的Require()似乎无法正常工作

另外,为什么var s = require('./simple');行会导致undefined响应?我使用节点v0.6.2

simple.js

var counts = 0; 
exports.next = function() { counts++; } 

我在REPL做

> var s = require('./simple'); 
undefined 
> s.next 
[Function] 
> s.next() 
undefined 
> s.next(); 
undefined 
+0

您是否在与文件相同的目录中启动REPL? – pradeek

+0

@pradeek是我在与'simple.js'文件相同的目录中输入了'node' – Nyxynyx

回答

3

这是完全正常的,因为你的函数实际上并不返回任何它会返回undefined默认情况下。试试这个exports.next = function() {return counts++; }你可以在添加之前得到数字。

相关问题