# make-objects-iterable
Because with this repo you'll be able to do this:
for ({ k, v } of object) {
// TODO
}
Other supported keys instead of k
or v
:
key
val
value
0
(fork
)1
(forv
)
This more classic syntax is also supported:
for ([k, v] of object) {
// TODO
}
Call makeObjectsIterable()
at the beginning of your app in order to modify the Object
prototype.
In Node 6 LTS.
I'm going to make a NPM module out of this repo, but please don't ask for an ETA.
Me.
Yes. They also make your code less FP-style. And functional programming is going to conquer the world. In fact, this repo is powerful, but with great power comes great responsibility. For example, you may define your own MyObject class, to make your code more explicit, but that's up to you.
Pros:
-
You can destructure both the n-th value and one or more of its sub-fields at once, like this:
for ({ k, v, v: { subField1 }, v: { subField1: { subField2 } } } of object) { console.log(subField1, subField2); // TODO }
You could not do this if you destructured with [key, value]
instead. Anyway, the [key, value]
syntax is also supported by this repo.
- The curly braces instead of the square brackets further clarify that the variable being iterated is an object
- If you don't need the key inside the
for...of
loop, you can just omit it
Like this:
for ({ k: anotherName, v: yetAnotherName } of object) {
console.log(anotherName, yetAnotherName);
// TODO
}
Study ES6 destructuring assignment on Mozilla Developer Network.