Personally I prefer a well known symbol for marking you are grabbing from
the end of the list rather than this wrapping behavior like D (
https://dlang.org/spec/arrays.html#array-length ). That said I think
`.last` is more reasonable than changing prototypes.

On Fri, Jan 22, 2016 at 1:17 PM, Dmitry Soshnikov <
dmitry.soshni...@gmail.com> wrote:

> On Fri, Jan 22, 2016 at 9:53 AM, RacerD123 <racerd...@gmail.com> wrote:
>
>> In other programming languages such as python, you can specify the last
>> element of a list with "list[-1]" but in javascript you have to do
>> "list[list.length-1]". Is there maybe a way to make this feature in
>> javascript?
>>
>>
> This could be a good addition, although `slice` may work as well. This has
> been discussed previously as well in the last 4-5 years. In addition with
> non-enumerable properties you can just monkey-patch `Array.prototype` with
> the `peek` or `last` method. I guess approach when some library forces some
> method to widely used, can be a good candidate for adding it to the spec
> (this how it was with `Function.prototype.bind`, e.g., although today
> monkey-patching is a bad practice of course).
>
> In addition, you can monkey-patch just `-1`, and other indexes, e.g. a
> gist from 5 years old, when a similar topic was proposed here:
> https://gist.github.com/DmitrySoshnikov/984921
>
> Dmitry
>
> _______________________________________________
> 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