Skip to content

Commit

Permalink
readline: refactor construct Interface
Browse files Browse the repository at this point in the history
Remove the dependency on the arguments.length.

PR-URL: #4740
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Trevor Norris <[email protected]>
Reviewed-By: Benjamin Gruenbaum <[email protected]>
  • Loading branch information
JacksonTian authored and MylesBorins committed Mar 9, 2017
1 parent 6e7dfb1 commit 396688f
Showing 1 changed file with 3 additions and 12 deletions.
15 changes: 3 additions & 12 deletions lib/readline.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,13 @@ const EventEmitter = require('events');


exports.createInterface = function(input, output, completer, terminal) {
var rl;
if (arguments.length === 1) {
rl = new Interface(input);
} else {
rl = new Interface(input, output, completer, terminal);
}
return rl;
return new Interface(input, output, completer, terminal);
};


function Interface(input, output, completer, terminal) {
if (!(this instanceof Interface)) {
// call the constructor preserving original number of arguments
const self = Object.create(Interface.prototype);
Interface.apply(self, arguments);
return self;
return new Interface(input, output, completer, terminal);
}

this._sawReturn = false;
Expand All @@ -41,7 +32,7 @@ function Interface(input, output, completer, terminal) {
EventEmitter.call(this);
var historySize;

if (arguments.length === 1) {
if (input && input.input) {
// an options object was given
output = input.output;
completer = input.completer;
Expand Down

0 comments on commit 396688f

Please sign in to comment.