Providing object iterators beyond just Object.keys()

Gijs Kruitbosch gijskruitbosch at gmail.com
Tue May 26 15:33:12 UTC 2015


Hello,

When writing JS loops over objects, given the environment I'm in, I find
myself using the gecko/spidermonkey-only "Iterator()" construct a lot for
loops or array comprehensions:

for (let [key, val] of Iterator(plainJSObject)) {
   // do stuff with both key and val
}

It seems the plan is to remove "Iterator()" (cf.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Iterator
).

Are there plans to add things like Object.values() (to produce
Object.keys(obj).map(k => obj[k]) ) or Object.iterator
(Object.keys(obj).map(k => [k, obj[k]])) so as to enable such usecases to
be written easily in ES7 or later? Obviously I can create my own iterator,
but it starts to get tedious if I need to do this in every file where I
need to iterate over an object's own (enumerable) properties...

(using Maps here is difficult because writing hardcoded nested structures
of Maps is not nearly as neat as doing the same with Objects)

Gijs
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20150526/7215c37d/attachment.html>


More information about the es-discuss mailing list