-
-
Save caitp/db5eae82a62b27d9e8ee9f7ab6b20a01 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function* EnumerateObjectProperties(obj) { | |
const visited = new Set(); | |
- for (const key of Reflect.ownKeys(obj)) { | |
+ const keys = Reflect.ownKeys(obj) | |
+ .filter(key => typeof key !== "symbol" && (key = Reflect.getOwnPropertyDescriptor(obj, key)) && key.enumerable); | |
+ for (const key of keys) { | |
- if (typeof key === "symbol") continue; | |
const desc = Reflect.getOwnPropertyDescriptor(obj, key); | |
if (desc) { | |
visited.add(key); | |
- if (desc.enumerable) yield key; | |
+ yield key; | |
} | |
} | |
const proto = Reflect.getPrototypeOf(obj); | |
if (proto === null) return; | |
for (const protoKey of EnumerateObjectProperties(proto)) { | |
if (!visited.has(protoKey)) yield protoKey; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment