isiahmeadows at gmail.com
Tue Jul 10 04:15:12 UTC 2018
I like the idea, but there's a few tweaks I think could be made:
1. `replace` reads like you're doing a string or subarray replace.
This proposal sounds more like an `update`.
2. If you allow it to carry the semantics of `slice()` + `array[index]
= value`, engines can implement it a bit quicker.
3. IMHO, this belongs as syntax, either in addition or in place of
this proposal's method. If nothing else, it's for consistency with
object spread, but it also allows you to spread iterables similarly,
something like `[...iter, index: value]`. We could also introduce that
as an array pattern type, so we don't need to use elisions so
frequently to skip values in array destructuring patterns (think:
`regexp.exec(string)` results, when you don't care about all the
groups). There's been times where I've had upwards of 3-4 elisions all
clustered together, and that gets unreadable in a hurry.
me at isiahmeadows.com
On Mon, Jul 9, 2018 at 11:42 PM, Ben Wiley <therealbenwiley at gmail.com> wrote:
> Hi ECMAScript folks,
> I'm brand new to this process and I've drafted a proposal (and polyfill) for
> a new Array.prototype.replace method. In the vein of Array concat, String
> replace and the new Object rest spread, Array replace provides a way to
> shallow clone an array and replace an element in a single statement.
> Here's the GitHub repo, which outlines API, motivation, use cases,
> alternatives, and polyfill usage:
> Array replace shouldn't be considered an across-the-board substitute for
> Array.prototype.splice (which mutates the array) and wouldn't be ideal for
> performance critical applications handling very large arrays. It is well
> suited for application logic where immutability is desired - a trend growing
> Most of the application areas of object rest spread composition syntax (for
> building objects, not destructuring them) are also application areas for
> Array.prototype.replace, when your object happens to be an array.
> I'm looking forward to any feedback and I'd also love for a champion to step
> in and help, if you think this is an ok idea.
> es-discuss mailing list
> es-discuss at mozilla.org
More information about the es-discuss