Skip to content

Instantly share code, notes, and snippets.

@allenwb allenwb/enumerate.js
Created Jul 18, 2014

What would you like to do?
[[Enumerate]] in JS code
function *enumerate(obj) {
if (Object(obj)!==obj) return undefined;
let visited = new Set;
while (obj!==null ) {
for (name of Object.getOwnPropertyNames(obj)) {
if (!visited.has(name)) {
let desc = Object.getOwnPropertyDescriptor(obj,name);
if (desc) {
if (desc.enumerable) yield name;
obj = Object.getPrototypeOf(obj);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.