Live data from Hacker News

Stage 3 Proposal: Array.prototype.at

tc39.es

1–10 of 153 posts

Re: Stage 3 Proposal: Array.prototype.at

#7
post #2

Am I reading this correctly — it's an alias for arr[i] and str[i]? I know languages like Ruby have arr.at(i), but why?

In addition to negative index support, a function is more easily composable e.g. converting a list of indices to a list of objects: `indices.map(myObjectArr.at)`

I've lost count on how many times I've wrote this function manually.

Re: Stage 3 Proposal: Array.prototype.at

#8
post #3
post #2

Am I reading this correctly — it's an alias for arr[i] and str[i]? I know languages like Ruby have arr.at(i), but why?

A quick read suggests that it adds negative indexing from the end of the array.

Imho that violates the principle of least astonishment - that "at" would have such different behavior from "[]" for negative numbers.

Re: Stage 3 Proposal: Array.prototype.at

#10

So instead of fixing the language and allow to use array[-1], they add an other way to access array element. This is why I don't like JavaScript, instead of fixing feature, they add new feature to fix previous feature.

The problem with JS language development is the mountain of code that it would break if you do anything except append features.

    array[-1] = “foo”
This already works in JS but doesn’t do what you expect and just assigns the property.
Post reply on HN