Skip to content

Instantly share code, notes, and snippets.

@caitp
Last active April 23, 2019 21:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save caitp/db5eae82a62b27d9e8ee9f7ab6b20a01 to your computer and use it in GitHub Desktop.
Save caitp/db5eae82a62b27d9e8ee9f7ab6b20a01 to your computer and use it in GitHub Desktop.
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