Skip to content

Commit 22040dc

Browse files
ehmickysindresorhus
andauthoredJul 30, 2022
Remove propertyIsEnumerable() (#26)
Co-authored-by: Sindre Sorhus <sindresorhus@gmail.com>
1 parent 6a80123 commit 22040dc

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed
 

‎index.js

+5-7
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,18 @@ export function includeKeys(object, predicate) {
33

44
if (Array.isArray(predicate)) {
55
for (const key of predicate) {
6-
if (isEnumerable.call(object, key)) {
7-
const descriptor = Object.getOwnPropertyDescriptor(object, key);
6+
const descriptor = Object.getOwnPropertyDescriptor(object, key);
7+
if (descriptor?.enumerable) {
88
Object.defineProperty(result, key, descriptor);
99
}
1010
}
1111
} else {
12-
// `for ... of Reflect.ownKeys()` is faster than `for ... of Object.entries()`.
12+
// `Reflect.ownKeys()` is required to retrieve symbol properties
1313
for (const key of Reflect.ownKeys(object)) {
14-
if (isEnumerable.call(object, key)) {
14+
const descriptor = Object.getOwnPropertyDescriptor(object, key);
15+
if (descriptor.enumerable) {
1516
const value = object[key];
1617
if (predicate(key, value, object)) {
17-
const descriptor = Object.getOwnPropertyDescriptor(object, key);
1818
Object.defineProperty(result, key, descriptor);
1919
}
2020
}
@@ -24,8 +24,6 @@ export function includeKeys(object, predicate) {
2424
return result;
2525
}
2626

27-
const {propertyIsEnumerable: isEnumerable} = Object.prototype;
28-
2927
export function excludeKeys(object, predicate) {
3028
if (Array.isArray(predicate)) {
3129
const set = new Set(predicate);

0 commit comments

Comments
 (0)
Please sign in to comment.