Additional methods for Objects (like Arrays)

Jordan Harband ljharb at gmail.com
Fri Feb 5 19:26:37 UTC 2016


Object.entries and Object.values must remain consistent with Object.keys
and will return arrays - luckily those are iterable too.

On Friday, February 5, 2016, Isiah Meadows <isiahmeadows at gmail.com> wrote:

> I think that these methods should exist in iterator prototypes, with the
> native iterators subclassing something like Iterator. Object.entries and
> Object.values should return iterators that inherit these methods. Such
> wrapper libraries are already coming out, and making existing arrays lazily
> iterate already exists in `Symbol.iterator`.
>
> On Tue, Feb 2, 2016, 12:12 Simon Blackwell <syblackwell at anywhichway.com
> <javascript:_e(%7B%7D,'cvml','syblackwell at anywhichway.com');>> wrote:
>
>> Although Rick makes a good point that Object.values and Object.entries
>> make creating functionality similar to that describe by Kaustubh, they are
>> no exactly direct. We have added the requested functions to V2.0 of
>> JavaScript Object Extensions at https://github.com/anywhichway/joex.
>>
>>
>> On Fri, Jan 29, 2016 at 7:44 PM, Rick Waldron <waldron.rick at gmail.com
>> <javascript:_e(%7B%7D,'cvml','waldron.rick at gmail.com');>> wrote:
>>
>>>
>>>
>>> On Fri, Jan 29, 2016 at 6:08 PM Kaustubh Karkare <
>>> kaustubh.karkare at gmail.com
>>> <javascript:_e(%7B%7D,'cvml','kaustubh.karkare at gmail.com');>> wrote:
>>>
>>>> I have recently come to feel the need for Object.map, which is like
>>>> Array.map,
>>>> except that it receive keys instead of indices.
>>>>
>>>> Object.prototype.map = function(mapFn, context) {
>>>>   return Object.keys(this)
>>>>     .reduce(function(result, key) {
>>>>       result[key] = mapFn.call(context, this[key], key, this);
>>>>       return result;
>>>>     }, {});
>>>> };
>>>>
>>>> Without this, I frequently do the exact same thing as the above
>>>> manually,
>>>> which leads to unnecessary code duplication.
>>>>
>>>> Given that, it might make sense to match other methods from
>>>> Array.prototype
>>>>
>>>> Object.map
>>>> Object.filter
>>>> Object.every
>>>> Object.some
>>>> Object.reduce
>>>> Object.find
>>>> Object.findKey // like Array.findIndex
>>>>
>>>
>>>
>>> Are these necessary given the introduction of Object.values() and
>>> Object.entries()? https://github.com/tc39/proposal-object-values-entries
>>>
>>> Rick
>>>
>>> _______________________________________________
>>> es-discuss mailing list
>>> es-discuss at mozilla.org
>>> <javascript:_e(%7B%7D,'cvml','es-discuss at mozilla.org');>
>>> https://mail.mozilla.org/listinfo/es-discuss
>>>
>>>
>> _______________________________________________
>> es-discuss mailing list
>> es-discuss at mozilla.org
>> <javascript:_e(%7B%7D,'cvml','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/20160205/a1733e19/attachment.html>


More information about the es-discuss mailing list