Initial commit
[yaffs-website] / node_modules / grunt-contrib-watch / node_modules / lodash / lang / isPlainObject.js
1 var baseForIn = require('../internal/baseForIn'),
2     isArguments = require('./isArguments'),
3     isObjectLike = require('../internal/isObjectLike');
4
5 /** `Object#toString` result references. */
6 var objectTag = '[object Object]';
7
8 /** Used for native method references. */
9 var objectProto = Object.prototype;
10
11 /** Used to check objects for own properties. */
12 var hasOwnProperty = objectProto.hasOwnProperty;
13
14 /**
15  * Used to resolve the [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring)
16  * of values.
17  */
18 var objToString = objectProto.toString;
19
20 /**
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`.
23  *
24  * **Note:** This method assumes objects created by the `Object` constructor
25  * have no inherited enumerable properties.
26  *
27  * @static
28  * @memberOf _
29  * @category Lang
30  * @param {*} value The value to check.
31  * @returns {boolean} Returns `true` if `value` is a plain object, else `false`.
32  * @example
33  *
34  * function Foo() {
35  *   this.a = 1;
36  * }
37  *
38  * _.isPlainObject(new Foo);
39  * // => false
40  *
41  * _.isPlainObject([1, 2, 3]);
42  * // => false
43  *
44  * _.isPlainObject({ 'x': 0, 'y': 0 });
45  * // => true
46  *
47  * _.isPlainObject(Object.create(null));
48  * // => true
49  */
50 function isPlainObject(value) {
51   var Ctor;
52
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)))) {
56     return false;
57   }
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.
61   var result;
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) {
66     result = key;
67   });
68   return result === undefined || hasOwnProperty.call(value, result);
69 }
70
71 module.exports = isPlainObject;