Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #20323
| From | Stefan Weiss <krewecherl@gmail.com> |
|---|---|
| Newsgroups | comp.lang.javascript |
| Subject | Re: Identifying a regex |
| Date | 2013-06-17 14:11 +0200 |
| Organization | albasani.net |
| Message-ID | <kpmudk$6ik$1@news.albasani.net> (permalink) |
| References | <kplir9$pj9$1@news.albasani.net> <1ms7xh1yugpt2.f0iyhdl4xbae$.dlg@40tude.net> |
On 2013-06-17 08:58, JJ wrote:
> On Mon, 17 Jun 2013 01:47:53 +0200, Stefan Weiss wrote:
>> What do you think is the best way to identify a value as a regular
>> expression (reference to a RegExp object)? I can see at least four
>> different ways, each with its own drawbacks:
>>
>> A) val instanceof RegExp
>> B) val.constructor.name == "RegExp"
>> C) Object.prototype.toString.call(val) == "[object RegExp]"
>> D) duck typing
>
> I've been using this kind of duck. Does it have a defect?
>
> isNativeCode = /\{[ \n]+\[native code\][ \n]+\}$/im;
> isRegExp = (val instanceof RegExp) &&
> isNativeCode.test(RegExp) && isNativeCode.test(RegExp.toString);
I don't understand what you're doing here...
The first test (val instanceof RegExp) is the method (A) I mentioned
earlier, and it will suffer from the same problem (cross-frame
identification).
The other tests just check the native RegExp object, not the value.
- stefan
Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Identifying a regex Stefan Weiss <krewecherl@gmail.com> - 2013-06-17 01:47 +0200
Re: Identifying a regex "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2013-06-16 19:30 -0700
Re: Identifying a regex Stefan Weiss <krewecherl@gmail.com> - 2013-06-17 14:05 +0200
Re: Identifying a regex "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2013-06-17 16:16 -0700
Re: Identifying a regex Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-06-18 02:13 +0200
Re: Identifying a regex Stefan Weiss <krewecherl@gmail.com> - 2013-06-18 20:14 +0200
Re: Identifying a regex Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-06-18 21:39 +0200
Re: Identifying a regex Stefan Weiss <krewecherl@gmail.com> - 2013-06-18 23:58 +0200
Re: Identifying a regex Stefan Weiss <krewecherl@gmail.com> - 2013-06-25 22:05 +0200
Re: Identifying a regex "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2013-06-25 16:59 -0700
Re: Identifying a regex Stefan Weiss <krewecherl@gmail.com> - 2013-06-26 23:47 +0200
Re: Identifying a regex Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-06-23 20:01 +0200
Re: Identifying a regex "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2013-06-18 00:40 -0700
Re: Identifying a regex Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-06-18 10:39 +0200
Re: Identifying a regex "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2013-06-18 19:32 -0700
Re: Identifying a regex Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-06-19 14:05 +0200
Re: Identifying a regex "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2013-06-19 20:24 -0700
Re: Identifying a regex Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-06-20 12:27 +0200
Re: Identifying a regex "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2013-06-20 18:08 -0700
Re: Identifying a regex JJ <duh@nah.meh> - 2013-06-17 13:58 +0700
Re: Identifying a regex Stefan Weiss <krewecherl@gmail.com> - 2013-06-17 14:11 +0200
Re: Identifying a regex JJ <duh@nah.meh> - 2013-06-18 12:46 +0700
Re: Identifying a regex Stefan Weiss <krewecherl@gmail.com> - 2013-06-18 20:17 +0200
Re: Identifying a regex Andreas Bergmaier <andber93@web.de> - 2013-06-18 21:14 +0200
csiph-web