我将 expressjs 与 nowjs 一起使用,当访问路由时,我将一些事件绑定到路由内的 now 对象。这不是很干净,我感觉所有的根都被访问了,事件被执行了。
我不知道怎么做,但我想知道我是否可以把它移到别处?
app.get('/room/:name', function(req, res)
{
//Should this code be moved elsewhere?... how?
nowjs.on('connect', function()
{
this.now.room = req.params.name;
nowjs.getGroup(this.now.room).addUser(this.user.clientId);
console.log("Joined: " + this.now.name);
});
everyone.now.distributeMessage = function(message){
nowjs.getGroup(this.now.room).now.receiveMessage(this.now.name, message);
};
res.render('room', { user : user });
});