Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #20313
| From | Stefan Weiss <krewecherl@gmail.com> |
|---|---|
| Newsgroups | comp.lang.javascript |
| Subject | Identifying a regex |
| Date | 2013-06-17 01:47 +0200 |
| Organization | albasani.net |
| Message-ID | <kplir9$pj9$1@news.albasani.net> (permalink) |
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 A selection of possible error sources: A) Has problems when the regex object was created in a different window (frame) from where it's being analyzed. B) The constructor property can be changed manually at any time. C) I've seen mention of failures in IE when the regex is created in another window (frame). Theoretically, a badly designed host object could also have an internal [[Class]] of "RegExp" and still be compliant with the standard, which only covers the [[Class]] names of native objects. D) It's probably a duck, but it might be a confused goose. I'm currently favoring option (B). The way I see it, if somebody messes around with the constructor property of a native object for no good reason, they're voiding their warranty. In addition, this test is not intended to be part of a general purpose library, which means that the number of potentially misbehaving users is very limited. Option (C) also looks promising, if the IE problem only affects older versions. Unfortunately, I can't test this, because my memory is maxed again and I can't launch any more VMs. I seriously need to upgrade... Looking forward to your thoughts about this. - stefan
Back to comp.lang.javascript | Previous | Next — 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