Re: Disambiguating the slash operator?
- "Douglas Crockford" <douglas@...> wrote:
> > return /^(?:[1-9]\d*|0)$/.test(val);...
> work, but there are problems in the language because it can be
> difficult to determine the meaning of / without doing a full parse.
> That is why I recommend that you write
> return (/^(?:[1-9]\d*|0)$/).test(val);
in regex literals could be ambiguous for either humans or the parser.
As far as I know, the parser always does a "full parse" in any case,
and the ECMAScript syntax doesn't contain any ambiguous passages that
I'm aware of. The same isn't always true for humans "parsing" code
(typical gotchas are automatic semicolon insertion, and assignments
where comparisons would be expected), so this JSLint message could
indeed be valuable for debugging. I've just never seen a case where
the slash was problematic.
I would be grateful if you or another subscriber on this list could
provide an example of such an ambiguous use of a regex literal.