Closed kmiller68 closed 6 years ago
Also, code like this:
const array = [1, 2, 3];
const itemIndex = array.indexOf(5); // -1
if (array[itemIndex]) {
// ...
}
Which is probably even more commonplace.
Absolutely, I'm faily certain this will pose as a web compat issue. I wanted to float the idea regardless, as it has been mentioned before and is something at least entertaining the idea to give ratified feedback as to why it cannot be done.
Closing this. The Readme has been updated to reflect the current state of this proposal.
The ECMAScript standard is not exactly easy to read but I could not locate a definitive statement that 'out of bounds array access must yield undefined', or similar falsey value. Does the spec require this? If not, the examples quoted above of code that would break if this proposal were implemented seem perverse to me. Why should forward progress (the arr[-N] proposal) be off-limits because a few individuals wrote such fragile code?
@john-aws for one, forward progress is always off limits if it would break the web - keeping websites working is far more important than any arbitrary syntax.
Have you looked into the compatibility of using '-1' as a accessor to the last element of an array? My concern is that there may be code in the wild like:
Which could break with your proposal.