From e56ee67e13c763bd4c73031bdccdfca2030e9bf4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Geisendo=CC=88rfer?= Date: Tue, 15 Feb 2011 08:47:30 -0500 Subject: [PATCH] Refactor fs.open parameter handling 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. --- lib/fs.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/fs.js b/lib/fs.js index 8cd15eb04e..62712d57f8 100644 --- a/lib/fs.js +++ b/lib/fs.js @@ -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) {