Initial commit
[yaffs-website] / node_modules / grunt-contrib-watch / node_modules / lodash / object / keys.js
1 var getNative = require('../internal/getNative'),
2     isArrayLike = require('../internal/isArrayLike'),
3     isObject = require('../lang/isObject'),
4     shimKeys = require('../internal/shimKeys');
5
6 /* Native method references for those with the same name as other `lodash` methods. */
7 var nativeKeys = getNative(Object, 'keys');
8
9 /**
10  * Creates an array of the own enumerable property names of `object`.
11  *
12  * **Note:** Non-object values are coerced to objects. See the
13  * [ES spec](http://ecma-international.org/ecma-262/6.0/#sec-object.keys)
14  * for more details.
15  *
16  * @static
17  * @memberOf _
18  * @category Object
19  * @param {Object} object The object to query.
20  * @returns {Array} Returns the array of property names.
21  * @example
22  *
23  * function Foo() {
24  *   this.a = 1;
25  *   this.b = 2;
26  * }
27  *
28  * Foo.prototype.c = 3;
29  *
30  * _.keys(new Foo);
31  * // => ['a', 'b'] (iteration order is not guaranteed)
32  *
33  * _.keys('hi');
34  * // => ['0', '1']
35  */
36 var keys = !nativeKeys ? shimKeys : function(object) {
37   var Ctor = object == null ? undefined : object.constructor;
38   if ((typeof Ctor == 'function' && Ctor.prototype === object) ||
39       (typeof object != 'function' && isArrayLike(object))) {
40     return shimKeys(object);
41   }
42   return isObject(object) ? nativeKeys(object) : [];
43 };
44
45 module.exports = keys;