Skip to content

Commit ad5b715

Browse files
apapirovskiMylesBorins
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 4e67d38 commit ad5b715

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
@@ -121,7 +121,7 @@ class FileHandle {
121121
return writeFile(this, data, options);
122122
}
123123

124-
close() {
124+
close = () => {
125125
return this[kHandle].close();
126126
}
127127
}
@@ -425,7 +425,7 @@ async function lchmod(path, mode) {
425425
throw new ERR_METHOD_NOT_IMPLEMENTED('lchmod()');
426426

427427
const fd = await open(path, O_WRONLY | O_SYMLINK);
428-
return fchmod(fd, mode).finally(fd.close.bind(fd));
428+
return fchmod(fd, mode).finally(fd.close);
429429
}
430430

431431
async function lchown(path, uid, gid) {
@@ -490,7 +490,7 @@ async function writeFile(path, data, options) {
490490
return writeFileHandle(path, data, options);
491491

492492
const fd = await open(path, flag, options.mode);
493-
return writeFileHandle(fd, data, options).finally(fd.close.bind(fd));
493+
return writeFileHandle(fd, data, options).finally(fd.close);
494494
}
495495

496496
async function appendFile(path, data, options) {
@@ -508,7 +508,7 @@ async function readFile(path, options) {
508508
return readFileHandle(path, options);
509509

510510
const fd = await open(path, flag, 0o666);
511-
return readFileHandle(fd, options).finally(fd.close.bind(fd));
511+
return readFileHandle(fd, options).finally(fd.close);
512512
}
513513

514514
module.exports = {

lib/internal/fs/streams.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ WriteStream.prototype.close = function(cb) {
442442
// If we are not autoClosing, we should call
443443
// destroy on 'finish'.
444444
if (!this.autoClose) {
445-
this.on('finish', this.destroy.bind(this));
445+
this.on('finish', this.destroy);
446446
}
447447

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

0 commit comments

Comments
 (0)