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.
pull/5370/head
isaacs 2011-06-04 10:38:49 -07:00
parent e142fe2be6
commit 580ab7ba2c
1 changed files with 2 additions and 2 deletions

View File

@ -1437,12 +1437,12 @@ function getAgent(options) {
var _opts = {};
if (options instanceof String) {
if (typeof options === 'string') {
port = arguments[1] || 80;
id = options + ':' + port;
_opts.host = options;
_opts.port = port;
} else if (options instanceof Object) {
} else if (options && options === 'object') {
if (options.port || options.host) {
host = options.host || 'localhost';
port = options.port || 80;