From 87cb4db263864c72a8f5b2a165a71100f6399bb4 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Mon, 20 Jul 2015 08:10:30 -0700 Subject: [PATCH] Simplify `isHostObject`. --- lodash.js | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/lodash.js b/lodash.js index d712d32aa..cf92b310c 100644 --- a/lodash.js +++ b/lodash.js @@ -546,18 +546,17 @@ * @param {*} value The value to check. * @returns {boolean} Returns `true` if `value` is a host object, else `false`. */ - var isHostObject = (function() { - try { - Object({ 'toString': 0 } + ''); - } catch(e) { - return function() { return false; }; + function isHostObject(value) { + // Many host objects are `Object` objects that can coerce to strings + // despite having improperly defined `toString` methods. + var result = false; + if (value != null && typeof value.toString != 'function') { + try { + result = !!(value + ''); + } catch(e) {} } - return function(value) { - // Many host objects are `Object` objects that can coerce to strings - // despite having improperly defined `toString` methods. - return typeof value.toString != 'function' && typeof (value + '') == 'string'; - }; - }()); + return result; + } /** * Checks if `value` is object-like.