Loading ...
Sorry, an error occurred while loading the content.

345Re: Disambiguating the slash operator?

Expand Messages
  • Douglas Crockford
    Jan 8, 2009
    • 0 Attachment
      --- In jslint_com@yahoogroups.com, "crlender" <crlender@...> wrote:

      > This function:
      >
      > function isValidBZ (val) {
      > return /^(?:[1-9]\d*|0)$/.test(val);
      > }
      >
      > triggers the JSLint warning "Wrap the /regexp/ literal in parens
      > to disambiguate the slash operator". Could you clarify this? I
      > can't see any ambiguities in that line.

      This case is decidable, which is why JavaScript parsers are able to
      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);
    • Show all 3 messages in this topic