Я пишу простий сервер для Node.js і використовую власний клас, Userякий називається :
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));
}
};
а потім пізніше в процесі цього я багато інстантую:
var server = net.createServer(function (socket) {
/* other bugs */
var user = new User(socket);
/* more bugs and bad practise */
});
Чи можу я перенести Userвизначення свого класу в інший файл javascript і якось "включити" його?