Sto scrivendo un semplice server per Node.js e sto usando la mia classe chiamata Userche assomiglia 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));
}
};
e poi più avanti nel processo ne creo molte istanze:
var server = net.createServer(function (socket) {
/* other bugs */
var user = new User(socket);
/* more bugs and bad practise */
});
Posso spostare la Userdefinizione della mia classe in un altro file javascript e "includerla" in qualche modo?