Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
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.
  • Loading branch information
apapirovski committed Dec 13, 2019
commit 396e428bf9859180b6139584d7de85ca5d77f271
8 changes: 4 additions & 4 deletions lib/internal/fs/promises.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ class FileHandle {
return writeFile(this, data, options);
}

close() {
close = () => {
return this[kHandle].close();
}
}
Expand Down Expand Up @@ -425,7 +425,7 @@ async function lchmod(path, mode) {
throw new ERR_METHOD_NOT_IMPLEMENTED('lchmod()');

const fd = await open(path, O_WRONLY | O_SYMLINK);
return fchmod(fd, mode).finally(fd.close.bind(fd));
return fchmod(fd, mode).finally(fd.close);
}

async function lchown(path, uid, gid) {
Expand Down Expand Up @@ -490,7 +490,7 @@ async function writeFile(path, data, options) {
return writeFileHandle(path, data, options);

const fd = await open(path, flag, options.mode);
return writeFileHandle(fd, data, options).finally(fd.close.bind(fd));
return writeFileHandle(fd, data, options).finally(fd.close);
}

async function appendFile(path, data, options) {
Expand All @@ -508,7 +508,7 @@ async function readFile(path, options) {
return readFileHandle(path, options);

const fd = await open(path, flag, 0o666);
return readFileHandle(fd, options).finally(fd.close.bind(fd));
return readFileHandle(fd, options).finally(fd.close);
}

module.exports = {
Expand Down
2 changes: 1 addition & 1 deletion lib/internal/fs/streams.js
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ WriteStream.prototype.close = function(cb) {
// If we are not autoClosing, we should call
// destroy on 'finish'.
if (!this.autoClose) {
this.on('finish', this.destroy.bind(this));
this.on('finish', this.destroy);
}

// We use end() instead of destroy() because of
Expand Down