On Fri, Jan 29, 2016 at 3:07 PM, Kaustubh Karkare <
kaustubh.kark...@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;
>     }, {});
> };
>
>
Also a potential issue of placing it on `Object.prototype` is that other
things will inherit it, including unrelated (like strings, regexps,
functions, etc). By this reason seems iterator methods `values`, `keys`,
and `entries` weren't added in ES6 to `Object.prototype`.

Dmitry



> 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
>
> Note that wherever applicable, the ordering is non-deterministic.
>
>
> _______________________________________________
> es-discuss mailing list
> es-discuss@mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
>
_______________________________________________
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to