Require()在REPL似乎不能正常工作
问题:我刚刚开始使用node.js,当使用REPL来require
一个模块时,它的函数一直显示为undefined。 哪里出了问题?
另外,为什么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
这是完全正常的,因为你的函数实际上并没有返回任何它会默认返回undefined的东西。 试试这个exports.next = function() {return counts++; }
你会在添加之前得到数字。