Created
May 9, 2013 15:24
-
-
Save allenwb/5548164 to your computer and use it in GitHub Desktop.
The ES5 for-in requirements expressed as an ES6 generator function
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 *forin(obj) { | |
let processed = new Set(); | |
while (obj!==null) { | |
let here = Object.getOwnPropertyNames(obj); | |
for (let i=0; i<here.length; i++) { | |
let name = here[i]; | |
if (processed.has(name)) continue; | |
processed.add(name); | |
let desc = Object.getOwnPropertyDescriptor(obj,name); | |
if (desc && 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