0

I cannot access to constructor property inside a callback function. Is there any way to access it.

My code:

constructor (config, socketHandler) {

    this.socketHandler = socketHandler;

    this.socketEventHandler = new SocketEventHandler();

}

listenSocketEvent () {

    this.socketHandler.on('connection', function (ws) {

        ws.on('message', function (message) {

            let response = JSON.parse(message);
            
             // Cannot access (undefined)
            this.socketEventHandler.handleEvent(response.event, response.d, ws);

        });

    });

0 Answers0