Skip to content

Commit 91845d8

Browse files
apapirovskitargos
authored andcommitted
fs: remove unnecessary bind
Don't use Function.prototype.bind where it isn't necessary. Rely on event emitter context instead and on arrow function as class property. PR-URL: #28131 Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Tobias Nießen <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]>
1 parent 01bb876 commit 91845d8

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

lib/internal/fs/promises.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ class FileHandle {
116116
return writeFile(this, data, options);
117117
}
118118

119-
close() {
119+
close = () => {
120120
return this[kHandle].close();
121121
}
122122
}
@@ -411,7 +411,7 @@ async function lchmod(path, mode) {
411411
throw new ERR_METHOD_NOT_IMPLEMENTED('lchmod()');
412412

413413
const fd = await open(path, O_WRONLY | O_SYMLINK);
414-
return fchmod(fd, mode).finally(fd.close.bind(fd));
414+
return fchmod(fd, mode).finally(fd.close);
415415
}
416416

417417
async function lchown(path, uid, gid) {
@@ -476,7 +476,7 @@ async function writeFile(path, data, options) {
476476
return writeFileHandle(path, data, options);
477477

478478
const fd = await open(path, flag, options.mode);
479-
return writeFileHandle(fd, data, options).finally(fd.close.bind(fd));
479+
return writeFileHandle(fd, data, options).finally(fd.close);
480480
}
481481

482482
async function appendFile(path, data, options) {
@@ -494,7 +494,7 @@ async function readFile(path, options) {
494494
return readFileHandle(path, options);
495495

496496
const fd = await open(path, flag, 0o666);
497-
return readFileHandle(fd, options).finally(fd.close.bind(fd));
497+
return readFileHandle(fd, options).finally(fd.close);
498498
}
499499

500500
module.exports = {

lib/internal/fs/streams.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ WriteStream.prototype.close = function(cb) {
372372
// If we are not autoClosing, we should call
373373
// destroy on 'finish'.
374374
if (!this.autoClose) {
375-
this.on('finish', this.destroy.bind(this));
375+
this.on('finish', this.destroy);
376376
}
377377

378378
// We use end() instead of destroy() because of

0 commit comments

Comments
 (0)