Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
80742 views
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
7
/** Used for native method references. */
8
var objectProto = Object.prototype;
9
10
/** Used to check objects for own properties. */
11
var hasOwnProperty = objectProto.hasOwnProperty;
12
13
/**
14
* Creates an array of the own and inherited enumerable property names of `object`.
15
*
16
* **Note:** Non-object values are coerced to objects.
17
*
18
* @static
19
* @memberOf _
20
* @category Object
21
* @param {Object} object The object to query.
22
* @returns {Array} Returns the array of property names.
23
* @example
24
*
25
* function Foo() {
26
* this.a = 1;
27
* this.b = 2;
28
* }
29
*
30
* Foo.prototype.c = 3;
31
*
32
* _.keysIn(new Foo);
33
* // => ['a', 'b', 'c'] (iteration order is not guaranteed)
34
*/
35
function keysIn(object) {
36
if (object == null) {
37
return [];
38
}
39
if (!isObject(object)) {
40
object = Object(object);
41
}
42
var length = object.length;
43
length = (length && isLength(length) &&
44
(isArray(object) || isArguments(object)) && length) || 0;
45
46
var Ctor = object.constructor,
47
index = -1,
48
isProto = typeof Ctor == 'function' && Ctor.prototype === object,
49
result = Array(length),
50
skipIndexes = length > 0;
51
52
while (++index < length) {
53
result[index] = (index + '');
54
}
55
for (var key in object) {
56
if (!(skipIndexes && isIndex(key, length)) &&
57
!(key == 'constructor' && (isProto || !hasOwnProperty.call(object, key)))) {
58
result.push(key);
59
}
60
}
61
return result;
62
}
63
64
module.exports = keysIn;
65
66