Avoid instanceof for native object types
For classes defined in the module, this is fine. For 'Error' it's probably not very hazardous. However, testing 'Object' and 'String' is much more reliable using typeof, to work with the repl and NODE_MODULE_CONTEXT modes.
This commit is contained in:
parent
e142fe2be6
commit
580ab7ba2c
@ -1437,12 +1437,12 @@ function getAgent(options) {
|
|||||||
|
|
||||||
var _opts = {};
|
var _opts = {};
|
||||||
|
|
||||||
if (options instanceof String) {
|
if (typeof options === 'string') {
|
||||||
port = arguments[1] || 80;
|
port = arguments[1] || 80;
|
||||||
id = options + ':' + port;
|
id = options + ':' + port;
|
||||||
_opts.host = options;
|
_opts.host = options;
|
||||||
_opts.port = port;
|
_opts.port = port;
|
||||||
} else if (options instanceof Object) {
|
} else if (options && options === 'object') {
|
||||||
if (options.port || options.host) {
|
if (options.port || options.host) {
|
||||||
host = options.host || 'localhost';
|
host = options.host || 'localhost';
|
||||||
port = options.port || 80;
|
port = options.port || 80;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user