Proposal: Array.prototype.first() and Array.prototype.last()
andrea.giammarchi at gmail.com
Tue Sep 27 14:26:11 UTC 2016
I don't think I've ever seen an `arr[-1]` access that wasn't meant to grab
last value same as `arr.slice(-1)` would do.
If you deal with arrays and you are treating them as generic objects and
you store numeric values like `-1` I'm not sure why would you do that or
what's your use case, all I know is that this will never be solved in TC39
so you can use a module and live happily ever after (really).
Reason for that:
* it's the most common use case
* nobody ever had issues with its implementation
On Tue, Sep 27, 2016 at 2:41 PM, Bob Myers <rtm at gol.com> wrote:
> > If you use `a.-1` to represent `a[length-1]`, so how do we refer to the
> value of the `-1` property?
> `a[-1]`, as at present.
> > It is obvious that ‘.’ before a number will be recognized as a decimal
> I don't think it's that obvious.
> I'm not a parsing guy, but I don't think the parser works backward,
> looking for dots preceding numbers.
> I would assume simplistically that a dot following an expression currently
> puts the parser into a mode where it is looking for the following
> identifier, so that logic could conceivably be tweaked to look
> alternatively for an integer index.
> `a.0` seems eminently parseable to me.
> On Tue, Sep 27, 2016 at 6:40 PM, Li Xiaolong <898310778 at outlook.com>
>> It is obvious that ‘.’ before a number will be recognized as a decimal
>> point, which is different from the point that gets a property. For example,
>> .2===0.2 is true. What’s more, the array’s prototype is object, which means
>> arr[-1] will get the value of -1 rather than length-1. The array can store
>> values at -1 like other objects. If you use -1 to represent length-1, so
>> how do we refer to the value of -1?
>> es-discuss mailing list
>> es-discuss at mozilla.org
> es-discuss mailing list
> es-discuss at mozilla.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the es-discuss