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클래스 정의를 다른 자바 스크립트 파일 로 이동 하고 어떻게 든 "포함"할 수 있습니까?