Simplify isHostObject.

This commit is contained in:
John-David Dalton
2015-07-20 08:10:30 -07:00
parent 2ccda44c44
commit 87cb4db263

View File

@@ -546,18 +546,17 @@
* @param {*} value The value to check. * @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is a host object, else `false`. * @returns {boolean} Returns `true` if `value` is a host object, else `false`.
*/ */
var isHostObject = (function() { function isHostObject(value) {
try {
Object({ 'toString': 0 } + '');
} catch(e) {
return function() { return false; };
}
return function(value) {
// Many host objects are `Object` objects that can coerce to strings // Many host objects are `Object` objects that can coerce to strings
// despite having improperly defined `toString` methods. // despite having improperly defined `toString` methods.
return typeof value.toString != 'function' && typeof (value + '') == 'string'; var result = false;
}; if (value != null && typeof value.toString != 'function') {
}()); try {
result = !!(value + '');
} catch(e) {}
}
return result;
}
/** /**
* Checks if `value` is object-like. * Checks if `value` is object-like.