Letting RegExp method return something iterable?

Andrea Giammarchi andrea.giammarchi at gmail.com
Mon Aug 26 17:19:53 PDT 2013


```javascript
{let m; while(m = re.exec(str)) {
  // ... no, really
}}
```
I don't get the need of this but if this is the trend then String#split
needs an iterable too (no!)




On Mon, Aug 26, 2013 at 4:23 PM, Brendan Eich <brendan at mozilla.com> wrote:

> Andrea Giammarchi wrote:
>
>> Is it very useful because you wrote for instead of while ?
>>
>> ```javascript
>> while (m = re.exec(str))
>>   console.log(m[0])
>> ;
>> ```
>>
>
> It is, for two reasons:
>
> 1. in JS only for can have a let or var binding in the head.
>
> 2. the utility extends to all for-of variations: array comprehensions,
> generator expresisons.
>
> /be
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20130826/b3ba848f/attachment.html>


More information about the es-discuss mailing list