Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
Refactor fs.open parameter handling
Browse files Browse the repository at this point in the history
Improvements:
* Removes an unnecessary variable
* Avoids having two variables with the same name
* Avoids re-declaring an existing parameter
* Removes an unnecessary ternary operator
* Avoid an inline short-circuit expression for greater clarity.
  • Loading branch information
felixge authored and ry committed Feb 15, 2011
1 parent aabdd5d commit e56ee67
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lib/fs.js
Expand Up @@ -185,12 +185,14 @@ function modeNum(m, def) {
}

fs.open = function(path, flags, mode, callback) {
var callback_ = arguments[arguments.length - 1];
var callback = (typeof(callback_) == 'function' ? callback_ : null);
callback = arguments[arguments.length - 1];
if (typeof(callback) !== 'function') {
callback = noop;
}

mode = modeNum(mode, '0666');

binding.open(path, stringToFlags(flags), mode, callback || noop);
binding.open(path, stringToFlags(flags), mode, callback);
};

fs.openSync = function(path, flags, mode) {
Expand Down

0 comments on commit e56ee67

Please sign in to comment.