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