我有node.js的问题。我正在创建一个博客,我有两个档案: sessions.js users.js
在sessions.js中:
function SessionsDAO(db) {
this.startSession = function(username, callback) {....}
}
module.exports.SessionsDAO = SessionsDAO;
在users.js
中var Session = require('./sessions');
var s = new Session();
s.startSession(username);
但显示错误:
object is not a function
TypeError: object is not a function
答案 0 :(得分:2)
require
返回exports
个对象,所以:
var SessionsDAO = require('./sessions').SessionsDAO;
var s = new SessionsDAO();
s.startSession(username);