Created
May 7, 2019 00:55
-
-
Save Tombarr/6a7423586ad9b0b3b0b1239ecf821d39 to your computer and use it in GitHub Desktop.
Make all Objects iterable in ES6
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
Object.prototype[Symbol.iterator] = function() { | |
let props = Object.getOwnPropertyNames(this); | |
return { | |
next: () => { | |
let name = props.shift(); | |
let done = (name === undefined); | |
let value = (done) ? undefined : [name, this[name]]; | |
return { value, done }; | |
} | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment