Object.values and/or Object.forEach ?

Erik Arvidsson erik.arvidsson at gmail.com
Fri Jun 7 17:33:45 PDT 2013


On Fri, Jun 7, 2013 at 7:05 PM, Andrea Giammarchi <
andrea.giammarchi at gmail.com> wrote:

> would this 'polyfill' as expected or there's more about these helpers ?
>

That would mostly work but these should be iterators (even though Array is
iterable so your incorrect polyfill would work fine in for-of).


>
> ```javascript
> this['@dict'] = {
>   keys: Object.keys,
>   values: function(keys){
>     function map(key) {
>       return this[key];
>     }
>     return function values(obj) {
>       return keys(obj).map(map, obj);
>     };
>   }(Object.keys),
>   entries: function(keys){
>     function map(key) {
>       return [key, this[key]];
>     }
>     return function entries(obj) {
>       return keys(obj).map(map, obj);
>     };
>   }(Object.keys)
> };
> ```
>
> Thanks
>
>
>
> On Fri, Jun 7, 2013 at 1:41 PM, Brian Di Palma <offler at gmail.com> wrote:
>
>> Surely the Map class would be used from now on for these use cases? It
>> seems ideal.
>> On Jun 7, 2013 7:21 PM, "Rick Waldron" <waldron.rick at gmail.com> wrote:
>>
>>>
>>>
>>>
>>> On Fri, Jun 7, 2013 at 1:25 PM, Brandon Benvie <bbenvie at mozilla.com>wrote:
>>>
>>>> On 6/7/2013 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.
>>>>>
>>>>
>>>> My impression was that the @dict module solves this as you suggest.
>>>>
>>>>     import { keys, values, entries } from '@dict';
>>>>
>>>>     let obj = { a: 1, b: 2, c: 3 };
>>>>
>>>>     for (let key of keys(obj)) {
>>>>       // ['a', 'b', 'c']
>>>>     }
>>>>
>>>>     for (let value of values(obj)) {
>>>>       // [1, 2, 3]
>>>>     }
>>>>
>>>>     for (let [key, value] of entries(obj)) {
>>>>       // [['a', 1], ['b', 2], ['c', 3]]
>>>>
>>>>     }
>>>>
>>>
>>>
>>> This is correct:
>>>
>>>
>>> https://github.com/rwldrn/tc39-notes/blob/master/es6/2012-11/nov-29.md#conclusionresolution-5
>>>
>>>
>>> Rick
>>>
>>>
>>>>  ______________________________**_________________
>>>> es-discuss mailing list
>>>> es-discuss at mozilla.org
>>>> https://mail.mozilla.org/**listinfo/es-discuss<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
>>
>>
>
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
>


-- 
erik
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20130607/12f91b54/attachment-0001.html>


More information about the es-discuss mailing list