From 65bb39aceebb333257b6ea409d7abbb160e1a318 Mon Sep 17 00:00:00 2001 From: pipi Date: Thu, 14 Feb 2019 22:18:39 +0800 Subject: [PATCH] Update index.js --- ch02-intro-to-node/listing_212/index.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ch02-intro-to-node/listing_212/index.js b/ch02-intro-to-node/listing_212/index.js index 71d0d13f..657b79a8 100644 --- a/ch02-intro-to-node/listing_212/index.js +++ b/ch02-intro-to-node/listing_212/index.js @@ -5,7 +5,7 @@ const channel = new events.EventEmitter(); channel.clients = {}; channel.subscriptions = {}; -channel.on('join', (id, client) => { +channel.on('join', function (id, client) { this.clients[id] = client; this.subscriptions[id] = (senderId, message) => { if (id != senderId) { @@ -15,9 +15,9 @@ channel.on('join', (id, client) => { this.on('broadcast', this.subscriptions[id]); }); -channel.on('leave', id => { - channel.removeListener('broadcast', this.subscriptions[id]); - channel.emit('broadcast', id, id + ' has left.\n'); +channel.on('leave', function (id) { + this.removeListener('broadcast', this.subscriptions[id]); + this.emit('broadcast', id, id + ' has left.\n'); }); const server = net.createServer(client => {