问题:我刚开始使用node.js,当使用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 :(得分:3)
这是完全正常的,因为你的函数实际上没有返回它默认返回undefined的任何东西。试试这个exports.next = function() {return counts++; }
,你就可以在加入之前得到这个数字。