Array.prototype.last()

Kris Kowal kris.kowal at cixar.com
Tue May 13 12:07:10 PDT 2014


I am in favor of last() and first() particularly because other collections
like queues and sorted sets can implement it and grow the common interface
of ordered collections. I also favor the last() and first() bike-shed
colors. I wrote a query and binding language that already uses these forms.

http://documentup.com/montagejs/frb/#tutorial/last

Kris Kowal


On Tue, May 13, 2014 at 11:54 AM, Dmitry Soshnikov <
dmitry.soshnikov at gmail.com> wrote:

> Hi,
>
> Exactly at the moment I'm writing too many of
>
>   entries[entries.length - 1]
>
> where `entries` is an array (with of course moving to a helper
> function/prototype method).
>
> Will it make sense to add it now to ES6?
>
> For consistency with Object.keys(), it could be exactly a function, not a
> getter:
>
> entries.last()
>
> For correlation with entries.length, it could be the getter, yes
>
> entries.last
>
> Both work well, just need to peek more practical.
>
> The pop() is similar, but removes the element.
>
> (the issue was discussed before, not sure whether it was decided not to
> include it, or was it's just forgotten - don't see it in the draft, but
> seems the useful thing: if not for ES6, probably for ES7)
>
> (Alternative: entries.peek())
>
> Dmitry
>
> _______________________________________________
> 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/20140513/e95dda0f/attachment.html>


More information about the es-discuss mailing list