mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-07 10:07:48 +00:00
Ensure _.isPlainObject returns true for empty objects in older browsers. [closes #283]
Former-commit-id: d01d32b1cbd87d08bc8014d07eaa1842e3118a40
This commit is contained in:
51
lodash.js
51
lodash.js
@@ -1026,34 +1026,33 @@
|
||||
* @returns {Boolean} Returns `true`, if `value` is a plain object, else `false`.
|
||||
*/
|
||||
function shimIsPlainObject(value) {
|
||||
// avoid non-objects and false positives for `arguments` objects
|
||||
var result = false;
|
||||
if (!(value && toString.call(value) == objectClass) || (!support.argsClass && isArguments(value))) {
|
||||
return result;
|
||||
}
|
||||
// check that the constructor is `Object` (i.e. `Object instanceof Object`)
|
||||
var ctor = value.constructor;
|
||||
var ctor,
|
||||
result;
|
||||
|
||||
if (isFunction(ctor) ? ctor instanceof ctor : (support.nodeClass || !isNode(value))) {
|
||||
// IE < 9 iterates inherited properties before own properties. If the first
|
||||
// iterated property is an object's own property then there are no inherited
|
||||
// enumerable properties.
|
||||
if (support.ownLast) {
|
||||
forIn(value, function(value, key, object) {
|
||||
result = hasOwnProperty.call(object, key);
|
||||
return false;
|
||||
});
|
||||
return result === true;
|
||||
}
|
||||
// In most environments an object's own properties are iterated before
|
||||
// its inherited properties. If the last iterated property is an object's
|
||||
// own property then there are no inherited enumerable properties.
|
||||
forIn(value, function(value, key) {
|
||||
result = key;
|
||||
});
|
||||
return result === false || hasOwnProperty.call(value, result);
|
||||
// avoid non Object objects, `arguments` objects, and DOM elements
|
||||
if (!(value && toString.call(value) == objectClass) ||
|
||||
(ctor = value.constructor, isFunction(ctor) && !(ctor instanceof ctor)) ||
|
||||
(!support.argsClass && isArguments(value)) ||
|
||||
(!support.nodeClass && isNode(value))) {
|
||||
return false;
|
||||
}
|
||||
return result;
|
||||
// IE < 9 iterates inherited properties before own properties. If the first
|
||||
// iterated property is an object's own property then there are no inherited
|
||||
// enumerable properties.
|
||||
if (support.ownLast) {
|
||||
forIn(value, function(value, key, object) {
|
||||
result = hasOwnProperty.call(object, key);
|
||||
return false;
|
||||
});
|
||||
return result !== false;
|
||||
}
|
||||
// In most environments an object's own properties are iterated before
|
||||
// its inherited properties. If the last iterated property is an object's
|
||||
// own property then there are no inherited enumerable properties.
|
||||
forIn(value, function(value, key) {
|
||||
result = key;
|
||||
});
|
||||
return result === undefined || hasOwnProperty.call(value, result);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user