Skip to content

Instantly share code, notes, and snippets.

@MeyCry
Created August 9, 2018 12:27
Show Gist options
  • Save MeyCry/9ecf8139f0a3a94c5753d0fa5bd8cb5f to your computer and use it in GitHub Desktop.
Save MeyCry/9ecf8139f0a3a94c5753d0fa5bd8cb5f to your computer and use it in GitHub Desktop.
/**
* @example for (let {key, val} of listeners) { console.log("2", key, val); }
*/
const listeners = {};
listeners[Symbol.iterator] = function () {
const keys = Object.keys(this);
const self = this;
var current = 0;
var last = keys.length;
return {
next() {
if (current < last) {
return {
done: false,
value: {
key: keys[current],
val: self[keys[current++]]
}
}
}
return {
done: true
}
}
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment