Estou escrevendo um servidor simples para Node.js e estou usando minha própria classe chamada, User
que se parece com:
function User(socket) {
this.socket = socket;
this.nickname = null;
/* ... just the typical source code like functions, variables and bugs ... */
this.write = function(object) {
this.socket.write(JSON.stringify(object));
}
};
e mais tarde no processo estou criando várias instâncias:
var server = net.createServer(function (socket) {
/* other bugs */
var user = new User(socket);
/* more bugs and bad practise */
});
Posso mover minha User
definição de classe para outro arquivo javascript e "incluí-lo" de alguma forma?