Node.js için basit bir sunucu yazıyorum ve Useraşağıdaki gibi görünen kendi sınıfımı kullanıyorum :
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));
}
};
ve daha sonra süreçte bunu çok fazla örneklendiriyorum:
var server = net.createServer(function (socket) {
/* other bugs */
var user = new User(socket);
/* more bugs and bad practise */
});
UserSınıf tanımımı başka bir javascript dosyasına taşıyıp bir şekilde "dahil edebilir miyim "?