How can I get Node.js class and socket.io event context?
<p>I have a Problem with the correct context in a JavaScript class and a socket.io 'disconnect' event.</p>

<p>My class looks like so:</p>

<pre><code>class GameSession {

   constructor(gameSessionId) {
       this._gameSessionId = gameSessionId;
       this._players = new Map();
   }

   addPlayer(socketId,player) {
       this._players.set(socketId,player);
       this.addListeners(player);
   }

   addListeners(player) {
       player.socket.on('disconnect',this.playerLeave);
   }

   playerLeave () {
       // ##### here is my Problem
   }
}
</code></pre>

<p>In the "playerLeave" function I can access the socket id with "this.id". But to access the "_players" map I need the context of the class which I get if I change the "addListeners" function to:</p>

<pre><code>addListeners(player) {
    player.socket.on('disconnect',() =&gt; this.playerLeave());
}
</code></pre>

<p>But by this I loose the context of the Event and so the possebility to call "this.id" to receive the socket id.</p>

<p>How can I get both?</p>