[英]Require() in REPL does not seem to work properly
Problem: I just started out in node.js and when using REPL to require
a module, its function keeps showing undefined. 问题:我刚开始使用node.js,当使用REPL
require
一个模块时,其功能始终显示为未定义。 Where did it go wrong? 哪里出错了?
Also, why does the var s = require('./simple');
另外,为什么
var s = require('./simple');
line result in an undefined
response? 行导致
undefined
响应? I am using node v0.6.2 我正在使用节点v0.6.2
simple.js simple.js
var counts = 0;
exports.next = function() { counts++; }
What I did in REPL 我在REPL做了什么
> var s = require('./simple');
undefined
> s.next
[Function]
> s.next()
undefined
> s.next();
undefined
That is completely normal, since your function doesn't actually return anything it would return undefined by default. 这是完全正常的,因为你的函数实际上并没有返回任何默认返回undefined的东西。 Try this
exports.next = function() {return counts++; }
试试这个
exports.next = function() {return counts++; }
exports.next = function() {return counts++; }
you get the number before the addition. exports.next = function() {return counts++; }
你得到的除了前面的数字。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.