1 var baseForIn = require('./baseForIn'),
2 isObjectLike = require('./isObjectLike');
4 /** `Object#toString` result references. */
5 var objectTag = '[object Object]';
7 /** Used for native method references. */
8 var objectProto = Object.prototype;
10 /** Used to check objects for own properties. */
11 var hasOwnProperty = objectProto.hasOwnProperty;
14 * Used to resolve the [`toStringTag`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-object.prototype.tostring)
17 var objToString = objectProto.toString;
20 * A fallback implementation of `_.isPlainObject` which checks if `value`
21 * is an object created by the `Object` constructor or has a `[[Prototype]]`
25 * @param {*} value The value to check.
26 * @returns {boolean} Returns `true` if `value` is a plain object, else `false`.
28 function shimIsPlainObject(value) {
31 // Exit early for non `Object` objects.
32 if (!(isObjectLike(value) && objToString.call(value) == objectTag) ||
33 (!hasOwnProperty.call(value, 'constructor') &&
34 (Ctor = value.constructor, typeof Ctor == 'function' && !(Ctor instanceof Ctor)))) {
37 // IE < 9 iterates inherited properties before own properties. If the first
38 // iterated property is an object's own property then there are no inherited
39 // enumerable properties.
41 // In most environments an object's own properties are iterated before
42 // its inherited properties. If the last iterated property is an object's
43 // own property then there are no inherited enumerable properties.
44 baseForIn(value, function(subValue, key) {
47 return result === undefined || hasOwnProperty.call(value, result);
50 module.exports = shimIsPlainObject;