Closed pgilad closed 7 years ago
How about hanging the named results off a new exec property hash, eg values
, whereby:
let {one, two} = /^(?<one>.*):(?<two>.*)$/.exec('foo:bar').values;
That would solve it
See discussion in the explainer of this. An earlier version of this proposal used a 'groups' object. I think that's too unergonomic, so I suggested just banning those properties. The prototype of match objects is null so there is no issue with Array methods.
@barneycarroll There is a big advantage to what you're suggesting, which is that it's future-proof for adding more properties to the match object (since it would be likely web-incompatible to create new early errors for using group names). I was previously thinking that this is unlikely to happen, but people keep raising this concern to me. Maybe it wouldn't be so unergonomic to put the named groups in a groups
property. Any thoughts? cc @bterlson
Not an issue because it's on the groups property.
There could be name collisions with
exec
result properties, namely:length
index
input
push
,pop
etc..)Should collisions be validated? Ignored? Rejected?