1
nodejs & socket.io 게임에 대한 간단한 클래스 (래퍼)를 만들려고합니다.TypeError : this.sendHandshake가 함수가 아닙니다.
module.exports = class client {
constructor(socket) {
this.socket = socket;
this.createEvents();
}
createEvents() {
console.log('creating events');
this.socket.on('handshake', this.onHandshake);
this.socket.on('disconnect', this.onDisconnect);
}
sendHandshake() { // <------------ sendHandshake is there?
console.log('sending handshake');
this.socket.emit('handshake');
}
onHandshake() {
console.log('handshake received');
this.sendHandshake(); // <----- TypeError: this.sendHandshake is not a function
}
onDisconnect() {
console.log('client disconnected');
}
}
그것은 나에게이 출력
creating events
handshake received
sending handshake
을 제공해야하지만, 대신 나에게 당신이 함수를 전달하는 경우
creating events
handshake received
TypeError: this.sendHandshake is not a function