Created
August 9, 2018 12:27
-
-
Save MeyCry/9ecf8139f0a3a94c5753d0fa5bd8cb5f to your computer and use it in GitHub Desktop.
This file contains hidden or 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
/** | |
* @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