JavaScript Language feature Idea

Frankie Bagnardi f.bagnardi at gmail.com
Sun Apr 17 21:29:48 UTC 2016


That would break backward compatibility;

```js
var a = ['a'];
a['-1'] = 'test';
Object.keys(a) // ['0', '-1']
```


On Sun, Apr 17, 2016 at 11:53 AM, Biju <bijumaillist at gmail.com> wrote:

> We cam make this simpler, in Javascript Array.slice() already accept
> negative index.
> Developers from Javascript and other languages are familiar with
> negative value for index parameter.
> So why cant we make array accept negative index.
>
> in comparison with Bob Myers' proposal
>
> > ```
> > [1,2,3](-1)
> > ```
>
> will become
>
> ```
>  [1,2,3][-1]
> ```
>
> This will also allow us to set value using negative index,
> example
>
> var array_data = [1, 2, 3, 4];
> array_data[-1] = 5;
> array_data[-3] = 6;
>
> // now array_data is [1, 6, 3, 5]
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20160417/b56d7bf8/attachment.html>


More information about the es-discuss mailing list