Firefox: for-of and objects

Erik Arvidsson erik.arvidsson at gmail.com
Thu Oct 25 09:46:20 PDT 2012


On Thu, Oct 25, 2012 at 11:50 AM, Jason Orendorff
<jason.orendorff at gmail.com> wrote:
> On Thu, Oct 25, 2012 at 6:24 AM, Axel Rauschmayer <axel at rauschma.de> wrote:
>> Sorry, slightly off-topic: Does Firefox already have @iter.items (etc.)? Or
>> is there something similar one could use to iterate over [key, value] pairs
>> for objects, via for-of?
>
> Unfortunately Iterator does do that, but I tend to think you'd be
> better off using Object.keys. Of course you can also write your own:
>
> function items(obj) {
>     return [[k, obj[k]] for (k of Object.keys(obj))];
> }

Don't you mean

function items(obj) {
    return ([k, obj[k]] for (k of Object.keys(obj)));
}

Generator comprehension instead of array comprehension... items is
suppused to return an iterable and in this case we don't need the
Array.

> -j
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss



-- 
erik


More information about the es-discuss mailing list