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:
isaacs 2011-06-04 10:38:49 -07:00
parent e142fe2be6
commit 580ab7ba2c

View File

@ -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;