From 580ab7ba2c1e0c89f351759b31f65bfed451ba9d Mon Sep 17 00:00:00 2001 From: isaacs Date: Sat, 4 Jun 2011 10:38:49 -0700 Subject: [PATCH] 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. --- lib/http.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/http.js b/lib/http.js index c18a8683df9..1a1e6d75457 100644 --- a/lib/http.js +++ b/lib/http.js @@ -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;