Array.prototype.replace

T.J. Crowder tj.crowder at farsightsoftware.com
Tue Jul 10 13:14:28 UTC 2018


On Tue, Jul 10, 2018 at 1:22 PM, Ben Wiley <therealbenwiley at gmail.com> wrote:
> Here's a spec question: must the keys specified be numbers? The application
> is questionable but I say anything could be allowed. E.g.
> ...
> So array rest spread would provide totally parallel functionality to object
> rest spread with the key difference that result objects are arrays instead
> of objects.

I'd call it a minor point. But off-the-cuff:

There's always a hopefully-creative tension between A) not
unnecessarily limiting things, and B) YAGNI and/or not handing people
footguns.

In the "don't unnecessarily limit" column:

* The ship has already sailed in terms of people confusing arrays and
objects in JavaScript.
* Not limiting to array index property names should mean the same
parsing structures and code can be used.
* I don't like unnecessary runtime checks, and the check that the
property name is an array index would have to be at runtime, not
parse-time, because of computed property names.
* Standard array indexes are officially strings anyway (though we
write them as numbers and they get optimized that way most of the
time).
* `[length: 10]` has a certain seductive quality about it.

In the YAGNI and/or footgun column:

* People already get objects and arrays confused enough! At least
right now, if they write `[foo: "bar"]`, they get a syntax error
(though of course `{0: "bar"}` is perfectly valid). Don't hand them
yet another footgun.
* As you say, application is questionable.

-- T.J. Crowder


More information about the es-discuss mailing list