mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-10 02:47:50 +00:00
Simplify isHostObject.
This commit is contained in:
21
lodash.js
21
lodash.js
@@ -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 {
|
// Many host objects are `Object` objects that can coerce to strings
|
||||||
Object({ 'toString': 0 } + '');
|
// despite having improperly defined `toString` methods.
|
||||||
} catch(e) {
|
var result = false;
|
||||||
return function() { return false; };
|
if (value != null && typeof value.toString != 'function') {
|
||||||
|
try {
|
||||||
|
result = !!(value + '');
|
||||||
|
} catch(e) {}
|
||||||
}
|
}
|
||||||
return function(value) {
|
return result;
|
||||||
// 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';
|
|
||||||
};
|
|
||||||
}());
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if `value` is object-like.
|
* Checks if `value` is object-like.
|
||||||
|
|||||||
Reference in New Issue
Block a user