If we're talking about adding a new method anyway, why not just add a
more general `get` method with support for both positive and negative
indices? That would be consistent with the other array methods, and
additionally I think it is more natural to use `arr.get(-2)` than
`arr.last(1)`. Using `last` to get anything but the very last element
just seems weird to me.
On 04/19/2016 10:00 AM, Bruno Jouhier wrote:
Adding `last` to `Array.prototype` is no different than adding
`endsWith` to `String.prototype`. ES2015 did it.
It won't break most existing code that defines `Array.prototype.last`.
Such code will just overwrite the new `last` method and will continue
to work as before.
You won't be able to mix old libraries that have their own `last`
method with new code if the methods behave differently but that's a
different story; that's not breaking existing web pages.
What will break though is existing code that test the existence of
`Array.prototype.last`; but `String.prototype.endsWith` had the same
issue.
last(1) would return last but one, and last() would be the same as last(0)
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss