Home |
RegExp API AddendumThanks to Zachary Carter and Steve Leviathan for pointing out that the issue identified in my previous article has already gotten some attention:
I'm relieved that I wasn't the only one scratching his head over this issue. I and others hope that this will be standardized for the next version of ECMAScript. The solution seems simple enough, except that I have one nitpick: it mixes up
both the compiled regular expression and the state of an an in-progress
match in a single That is, whether a match is exact or searching shouldn't be a property
of the Referring to Python's
API again, the
use of the This might seem like academic distinction in the browser, but JavaScript is used in many different contexts now. APIs should be designed with concurrency in mind. For example, say you are writing a concurrent web scraper. You may want to use
a Luckily, there's a simple and elegant solution that preserves compatibility
while making this distinction. I propose adding two optional positional
arguments to
Example call:
So then the two methods will follow this logic:
Likewise, for the match type:
The only valid This solution is easy to implement and preserves compatibility with both earlier ECMAScript versions and Mozilla's extensions in Firefox 3. |