I have a question about passing an instance, as following
app.js
// nodejs var
var app = express()
, server = http.createServer(app)
, _Server = io.listen(server);
/**
* To log
* Before, to display the _Server instance, the content should be
*/
console.log(util.inspect(_Server));
// app var
var _Session = new Session(_Server);
session.js
var Session = function Session(server) {
this.m_server = server;
/**
* To log
* After, to display the m_server property, the content actually is
*/
console.log(util.inspect(this.m_server));
}
I wonder why those results aren't the same as I expect. And as a result I couldn't call this.m_server.emit(...) in the Session class. What I want to do is to delegate a behavior
from
_Server.emit(...) // in app.js
to
this.m_server.emit(...) // in session.js
So that lots of events could be implemented in different files. How can I do to make it ? thanks~
try this:
app.js:
_Server = module.exports.io = io.listen(server);
session.js:
this.m_server = require('app').io;