From 8240c241d084aa9364e4a8ae81b85af152071b85 Mon Sep 17 00:00:00 2001 From: Vincent Weevers Date: Thu, 8 Apr 2021 14:54:05 +0200 Subject: [PATCH] Use arrow functions where `this` is needed --- abstract-iterator.js | 20 +++++++++----------- abstract-leveldown.js | 14 ++++++-------- 2 files changed, 15 insertions(+), 19 deletions(-) diff --git a/abstract-iterator.js b/abstract-iterator.js index b037dbc..4cec804 100644 --- a/abstract-iterator.js +++ b/abstract-iterator.js @@ -13,29 +13,27 @@ function AbstractIterator (db) { } AbstractIterator.prototype.next = function (callback) { - const self = this - if (typeof callback !== 'function') { throw new Error('next() requires a callback argument') } - if (self._ended) { + if (this._ended) { nextTick(callback, new Error('cannot call next() after end()')) - return self + return this } - if (self._nexting) { + if (this._nexting) { nextTick(callback, new Error('cannot call next() before previous next() has completed')) - return self + return this } - self._nexting = true - self._next(function () { - self._nexting = false - callback.apply(null, arguments) + this._nexting = true + this._next((err, ...rest) => { + this._nexting = false + callback(err, ...rest) }) - return self + return this } AbstractIterator.prototype._next = function (callback) { diff --git a/abstract-leveldown.js b/abstract-leveldown.js index c6b39cc..b9154be 100644 --- a/abstract-leveldown.js +++ b/abstract-leveldown.js @@ -18,7 +18,6 @@ function AbstractLevelDOWN (manifest) { } AbstractLevelDOWN.prototype.open = function (options, callback) { - const self = this const oldStatus = this.status if (typeof options === 'function') callback = options @@ -33,12 +32,12 @@ AbstractLevelDOWN.prototype.open = function (options, callback) { options.errorIfExists = !!options.errorIfExists this.status = 'opening' - this._open(options, function (err) { + this._open(options, (err) => { if (err) { - self.status = oldStatus + this.status = oldStatus return callback(err) } - self.status = 'open' + this.status = 'open' callback() }) } @@ -48,7 +47,6 @@ AbstractLevelDOWN.prototype._open = function (options, callback) { } AbstractLevelDOWN.prototype.close = function (callback) { - const self = this const oldStatus = this.status if (typeof callback !== 'function') { @@ -56,12 +54,12 @@ AbstractLevelDOWN.prototype.close = function (callback) { } this.status = 'closing' - this._close(function (err) { + this._close((err) => { if (err) { - self.status = oldStatus + this.status = oldStatus return callback(err) } - self.status = 'closed' + this.status = 'closed' callback() }) }