readline: refactor construct Interface
Remove the dependency on the arguments.length. PR-URL: https://github.com/nodejs/node/pull/4740 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Trevor Norris <trev.norris@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
This commit is contained in:
parent
57f6a106fb
commit
dad98bfe32
@ -23,22 +23,13 @@ const stripVTControlCharacters = internalReadline.stripVTControlCharacters;
|
|||||||
|
|
||||||
|
|
||||||
exports.createInterface = function(input, output, completer, terminal) {
|
exports.createInterface = function(input, output, completer, terminal) {
|
||||||
var rl;
|
return new Interface(input, output, completer, terminal);
|
||||||
if (arguments.length === 1) {
|
|
||||||
rl = new Interface(input);
|
|
||||||
} else {
|
|
||||||
rl = new Interface(input, output, completer, terminal);
|
|
||||||
}
|
|
||||||
return rl;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
function Interface(input, output, completer, terminal) {
|
function Interface(input, output, completer, terminal) {
|
||||||
if (!(this instanceof Interface)) {
|
if (!(this instanceof Interface)) {
|
||||||
// call the constructor preserving original number of arguments
|
return new Interface(input, output, completer, terminal);
|
||||||
const self = Object.create(Interface.prototype);
|
|
||||||
Interface.apply(self, arguments);
|
|
||||||
return self;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this._sawReturnAt = 0;
|
this._sawReturnAt = 0;
|
||||||
@ -51,7 +42,7 @@ function Interface(input, output, completer, terminal) {
|
|||||||
let crlfDelay;
|
let crlfDelay;
|
||||||
let prompt = '> ';
|
let prompt = '> ';
|
||||||
|
|
||||||
if (arguments.length === 1) {
|
if (input && input.input) {
|
||||||
// an options object was given
|
// an options object was given
|
||||||
output = input.output;
|
output = input.output;
|
||||||
completer = input.completer;
|
completer = input.completer;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user