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 <luigipinca@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
1 parent 01bb876 commit 91845d8

2 files changed

Lines changed: 5 additions & 5 deletions

File tree

‎lib/internal/fs/promises.js‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ class FileHandle {
116116
returnwriteFile(this,data,options);
117117
}
118118

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

413413
constfd=awaitopen(path,O_WRONLY|O_SYMLINK);
414-
returnfchmod(fd,mode).finally(fd.close.bind(fd));
414+
returnfchmod(fd,mode).finally(fd.close);
415415
}
416416

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

478478
constfd=awaitopen(path,flag,options.mode);
479-
returnwriteFileHandle(fd,data,options).finally(fd.close.bind(fd));
479+
returnwriteFileHandle(fd,data,options).finally(fd.close);
480480
}
481481

482482
asyncfunctionappendFile(path,data,options){
@@ -494,7 +494,7 @@ async function readFile(path, options) {
494494
returnreadFileHandle(path,options);
495495

496496
constfd=awaitopen(path,flag,0o666);
497-
returnreadFileHandle(fd,options).finally(fd.close.bind(fd));
497+
returnreadFileHandle(fd,options).finally(fd.close);
498498
}
499499

500500
module.exports={

‎lib/internal/fs/streams.js‎

Lines changed: 1 addition & 1 deletion
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)