Andrea Giammarchi andrea.giammarchi at gmail.com
Mon Jun 15 12:28:18 UTC 2015


You can't accept string or regexp 'cause strings cannot be flags this way
so beside split I don't know where this could work. flags like i, or u, are
also important, being unable to pass these even in split doesn't look like
a good idea, IMO

On Mon, Jun 15, 2015 at 1:22 PM, Denis Pushkarev <zloirock at zloirock.ru>
wrote:

> This logic is convenient if function accept string or regexp, like
> `String#split`, for convert it to regexp. Behavior with second argument is
> changed in ES6 and fixed in latest FF, `core-js` and `es6-shim`. Sorry for
> reply w/o subject - problem with mail client :)
>
> 15.06.2015, 17:36, "Andrea Giammarchi" <andrea.giammarchi at gmail.com>:
>
> that's no how usually you create RegExp
>
> ```js
> RegExp('yep', 'g');
> new RegExp('yep', 'g');
> ```
> both will produce similar RegExp instances (every time a new one).
>
> Using the RegExp constructor as RegExp wrapper is a very unusual pattern I
> haven't seen before. So yes, in that case we have some sort of unusual
> behavior that yet makes little sense to me because `RegExp.length` is 2 and
> you are potentially ignoring the second argument
>
> ```
> TypeError: Cannot supply flags when constructing one RegExp from another
> at new RegExp
> ```
>
> So beside creating a `new RegExp` from another `RegExp` knowing what you
> are doing is the only pattern I can think of that might make sense (in
> terms of having index and stuff reset ... if that's even the case)
>
> Good spot though.
>
> Regards
>
>
>
>
>
>
>
> On Mon, Jun 15, 2015 at 8:37 AM, Rock <zloirock at zloirock.ru> wrote:
>
> Benjamin Gruenaum, Andrea Giammarchi, you are wrong about RegExp:
> ```js
> var re = /./;
> new RegExp(re) === re; // false
> RegExp(re) === re; // true
> ```
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
>
>
> --
> С уважением,
> Denis Pushkarev
> 79619864927
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20150615/1ddc7d90/attachment.html>


More information about the es-discuss mailing list