2011-11-22 163 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++; }你可以在添加之前得到數字。

相關問題