Skip to content

Instantly share code, notes, and snippets.



Created May 9, 2013
What would you like to do?
The ES5 for-in requirements expressed as an ES6 generator function
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;
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