72a1c5e26e13a3fb3cbc8293b0a0aeef7dda8737
[platform/framework/web/crosswalk-tizen.git] /
1 var isArguments = require('../lang/isArguments'),
2     isArray = require('../lang/isArray'),
3     isIndex = require('../internal/isIndex'),
4     isLength = require('../internal/isLength'),
5     isObject = require('../lang/isObject'),
6     support = require('../support');
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  * Creates an array of the own and inherited enumerable property names of `object`.
16  *
17  * **Note:** Non-object values are coerced to objects.
18  *
19  * @static
20  * @memberOf _
21  * @category Object
22  * @param {Object} object The object to query.
23  * @returns {Array} Returns the array of property names.
24  * @example
25  *
26  * function Foo() {
27  *   this.a = 1;
28  *   this.b = 2;
29  * }
30  *
31  * Foo.prototype.c = 3;
32  *
33  * _.keysIn(new Foo);
34  * // => ['a', 'b', 'c'] (iteration order is not guaranteed)
35  */
36 function keysIn(object) {
37   if (object == null) {
38     return [];
39   }
40   if (!isObject(object)) {
41     object = Object(object);
42   }
43   var length = object.length;
44   length = (length && isLength(length) &&
45     (isArray(object) || (support.nonEnumArgs && isArguments(object))) && length) || 0;
46
47   var Ctor = object.constructor,
48       index = -1,
49       isProto = typeof Ctor == 'function' && Ctor.prototype === object,
50       result = Array(length),
51       skipIndexes = length > 0;
52
53   while (++index < length) {
54     result[index] = (index + '');
55   }
56   for (var key in object) {
57     if (!(skipIndexes && isIndex(key, length)) &&
58         !(key == 'constructor' && (isProto || !hasOwnProperty.call(object, key)))) {
59       result.push(key);
60     }
61   }
62   return result;
63 }
64
65 module.exports = keysIn;