Object.values and/or Object.forEach ?

Yehuda Katz wycats at gmail.com
Sat Jun 8 21:31:17 PDT 2013


Yehuda Katz
(ph) 718.877.1325


On Sat, Jun 8, 2013 at 9:23 PM, Dmitry Soshnikov <dmitry.soshnikov at gmail.com
> wrote:

> I might be missing something, but how for-of help solving parametrized
> enumeration (that is, specifying an action applied on a value/key in a
> functional style)?
>
> I see clear use-case of Object.values(...) in addition to
> Object.keys(...), and it has nothing to do with for/of enumeration.
>
> Why refuse a convenient library method and force users to 1) let values =
> []; 2) for (v of values(o)) { values.push(v); }, if it can be just let
> values = Object.values(o);?
>

I'm confused. Your example shows (correctly) that a `values` method exists
that does what you want. What more are you asking for?


> Why refuse a _parametrized_ functional iteration such as Object.forEach(o,
> parametrizedAction) and force users to write different static for-of loops
> with own loop body per each condition, if this condition can be passed as a
> function?
>

I am personally in favor of a collections module that works across any
iterable. I don't think we have anything on tap for ES6, but it would be
trivial to write in pure JS in the ES6 timeframe and I don't see any reason
it couldn't be folded in to ES7 once it gets some real-world usage.


> P.S.: for consistency with [].forEach, it probably would make sense having
> {}.forEach, but it's O.prototype pollution.
>
> Dmitry
>
> On Jun 7, 2013, at 10:18 AM, Dean Landolt wrote:
>
> The for/of iterators solve this nicely. This is definitely something that
> comes up a lot though, and this seems like a very handy cowpath to pave. If
> it were spec'd I'd suggest the naming and argument values should align with
> the for/of variants.
>
>
> On Fri, Jun 7, 2013 at 12:57 PM, Andrea Giammarchi <
> andrea.giammarchi at gmail.com> wrote:
>
>> it comes out from time to time devs would like to have `Object.values()`
>> as equivalent of `Object.keys()` except the returned array would contain
>> values.
>>
>> Better than repeated
>> `Object.keys(obj).map(function(p){return this[k];}, obj);`
>> all over
>>
>> but probably less useful than a more generic `Object.forEach(obj,
>> callback, thisValue)` where `callback` would receive `(value, key,
>> originalObject)` and `thisValue` as context.
>>
>> This is consistent with `Array#forEach` and could simplify `for/in` loops
>> passing over own enumerable properties only, as keys would do.
>>
>> Thoughts ?
>>
>> _______________________________________________
>> es-discuss mailing list
>> es-discuss at mozilla.org
>> https://mail.mozilla.org/listinfo/es-discuss
>>
>>
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
>
>
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20130608/afaa6932/attachment.html>


More information about the es-discuss mailing list