1 var baseForIn = require('../internal/baseForIn'),
2 isArguments = require('./isArguments'),
3 isObjectLike = require('../internal/isObjectLike');
5 /** `Object#toString` result references. */
6 var objectTag = '[object Object]';
8 /** Used for native method references. */
9 var objectProto = Object.prototype;
11 /** Used to check objects for own properties. */
12 var hasOwnProperty = objectProto.hasOwnProperty;
15 * Used to resolve the [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring)
18 var objToString = objectProto.toString;
21 * Checks if `value` is a plain object, that is, an object created by the
22 * `Object` constructor or one with a `[[Prototype]]` of `null`.
24 * **Note:** This method assumes objects created by the `Object` constructor
25 * have no inherited enumerable properties.
30 * @param {*} value The value to check.
31 * @returns {boolean} Returns `true` if `value` is a plain object, else `false`.
38 * _.isPlainObject(new Foo);
41 * _.isPlainObject([1, 2, 3]);
44 * _.isPlainObject({ 'x': 0, 'y': 0 });
47 * _.isPlainObject(Object.create(null));
50 function isPlainObject(value) {
53 // Exit early for non `Object` objects.
54 if (!(isObjectLike(value) && objToString.call(value) == objectTag && !isArguments(value)) ||
55 (!hasOwnProperty.call(value, 'constructor') && (Ctor = value.constructor, typeof Ctor == 'function' && !(Ctor instanceof Ctor)))) {
58 // IE < 9 iterates inherited properties before own properties. If the first
59 // iterated property is an object's own property then there are no inherited
60 // enumerable properties.
62 // In most environments an object's own properties are iterated before
63 // its inherited properties. If the last iterated property is an object's
64 // own property then there are no inherited enumerable properties.
65 baseForIn(value, function(subValue, key) {
68 return result === undefined || hasOwnProperty.call(value, result);
71 module.exports = isPlainObject;