Incluyendo la definición de clase de JavaScript de otro archivo en Node.js
Estoy escribiendo un servidor simple para Node.js y estoy usando mi propia clase llamadaUser
que se parece a:
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));
}
};
y luego, más adelante en el proceso, lo instanciaré mucho:
var server = net.createServer(function (socket) {
/* other bugs */
var user = new User(socket);
/* more bugs and bad practise */
});
¿Puedo mover miUser
definición de clase a otro archivo javascript y "incluirlo" de alguna manera?