Throwing StopIteration in array extras to stop the iteration

Andrea Giammarchi andrea.giammarchi at gmail.com
Mon Mar 4 08:38:19 PST 2013


I use RegExp.$1 , RegExp.$2, etc quite a lot since I am a huge fan of the
RAM and I believe creating a redundant array of matches for no reason since
these are retrievable in any case through the RegExp constructor,
considering exec and match points to those RegExp properties anyhow, ain't
needed when re.test(value) is involved.

If re.test(value) RegExp.$1;

As easy as that: 1) is *not* a bad practice and 2) is less redundant than
if (re.test(value)) match = re.exec(value)[1];

I might agree about the ugly ness, the fact MDN is lacking those properties
I believe defined in the specs does not mean those properties are bad (as I
have just explained)

Also, that does not find a thing, that find an index ... and I forgot the
+RegExp['$&'] plus sign to have the integer.

We are programmers, we find solutions/alternatives/optimizations ... right?

br



On Mon, Mar 4, 2013 at 8:24 AM, Jeff Walden <jwalden+es at mit.edu> wrote:

> On 03/03/2013 06:53 PM, Andrea Giammarchi wrote:
> > I had to check msdn rather than MDN since latter does not mention it
> while mans shows an example:
> http://msdn.microsoft.com/en-us/library/ie/3k9c4a32(v=vs.94).aspx
>
> The RegExp statics aren't mentioned because they're a bad idea, imposing
> costs of some sort on pretty much all regular expression uses.  Don't use
> them!
>
> And, um, this is quite possibly the most awful way to find a value in an
> array that I've ever seen.  Even setting aside the statics usage!
>
> Jeff
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20130304/fb115402/attachment-0001.html>


More information about the es-discuss mailing list