From ec9de31d152f0b65a46649f775fe302bf4cc489f Mon Sep 17 00:00:00 2001 From: Daniel Lando Date: Tue, 18 Jul 2023 15:49:04 +0200 Subject: [PATCH] fix: useless bind --- lib/client.js | 4 ++-- test/abstract_client.js | 17 ++++++++--------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/lib/client.js b/lib/client.js index 014191d8d..4dec273fb 100644 --- a/lib/client.js +++ b/lib/client.js @@ -317,7 +317,7 @@ class MqttClient extends EventEmitter { this.stream.pipe(writable) // Suppress connection errors - this.stream.on('error', streamErrorHandler.bind(this)) + this.stream.on('error', streamErrorHandler) // Echo stream close this.stream.on('close', () => { @@ -890,7 +890,7 @@ class MqttClient extends EventEmitter { 'end :: finish :: calling process.nextTick on closeStores', ) // const boundProcess = nextTick.bind(null, closeStores) - nextTick(closeStores.bind(this)) + nextTick(closeStores) }, opts, ) diff --git a/test/abstract_client.js b/test/abstract_client.js index f85e47903..8cb35b2fc 100644 --- a/test/abstract_client.js +++ b/test/abstract_client.js @@ -180,7 +180,7 @@ module.exports = (server, config) => { const client = connect() client.once('end', () => { - const timeout = setTimeout(done.bind(null), 200) + const timeout = setTimeout(() => done(), 200) client.once('end', () => { clearTimeout(timeout) done(new Error('end was emitted twice')) @@ -188,7 +188,9 @@ module.exports = (server, config) => { client.end() }) - client.once('connect', client.end.bind(client)) + client.once('connect', () => { + client.end() + }) }) it('should stop ping timer after end called', function _test(done) { @@ -232,8 +234,7 @@ module.exports = (server, config) => { // after 200ms manually invoke client.end setTimeout(() => { - const boundEnd = client.end.bind(client) - boundEnd() + client.end.callbind(client) }, 200) }) @@ -247,7 +248,7 @@ module.exports = (server, config) => { connectTimeout: 10, reconnectPeriod: 20, }) - setTimeout(done.bind(null), 1000) + setTimeout(() => done(), 1000) const endCallback = () => { assert.strictEqual( spy.callCount, @@ -259,8 +260,7 @@ module.exports = (server, config) => { const spy = sinon.spy(endCallback) client.on('end', spy) setTimeout(() => { - client.end.bind(client) - client.end() + client.end.call(client) }, 300) }) }) @@ -2887,8 +2887,7 @@ module.exports = (server, config) => { }) // bind client.end so that when it is called it is automatically passed in the done callback setTimeout(() => { - const boundEnd = client.end.bind(client, done) - boundEnd() + client.end.call(client, done) }, 50) })