From 74f76f66838a5e2b6a40ae7e0cac934a79e58c31 Mon Sep 17 00:00:00 2001 From: Guy Fraser Date: Sat, 25 Jun 2016 02:11:17 +0100 Subject: [PATCH] debugger: use arrow function for lexical `this` Refs: https://github.com/nodejs/node/issues/7414 PR-URL: https://github.com/nodejs/node/pull/7415 Reviewed-By: Colin Ihrig Reviewed-By: James M Snell Reviewed-By: Brian White --- lib/_debug_agent.js | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/lib/_debug_agent.js b/lib/_debug_agent.js index cb4684f0eddfac..3457c6db8ac9d6 100644 --- a/lib/_debug_agent.js +++ b/lib/_debug_agent.js @@ -50,9 +50,8 @@ function Agent() { this.binding = process._debugAPI; assert(this.binding, 'Debugger agent running without bindings!'); - var self = this; - this.binding.onmessage = function(msg) { - self.clients.forEach(function(client) { + this.binding.onmessage = (msg) => { + this.clients.forEach((client) => { client.send({}, msg); }); }; @@ -67,11 +66,10 @@ Agent.prototype.onConnection = function onConnection(socket) { c.start(); this.clients.push(c); - var self = this; - c.once('close', function() { - var index = self.clients.indexOf(c); + c.once('close', () => { + var index = this.clients.indexOf(c); assert(index !== -1); - self.clients.splice(index, 1); + this.clients.splice(index, 1); }); }; @@ -98,9 +96,8 @@ function Client(agent, socket) { this.on('data', this.onCommand); - var self = this; - this.socket.on('close', function() { - self.destroy(); + this.socket.on('close', () => { + this.destroy(); }); } util.inherits(Client, Transform);