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

Re: Good and bad invocation, a.k.a. call a RegExp

Expand Messages
  • Christian
    JSLint helps to use a proper subset of Javascript. Javascript has a lot of issues which JSLint tries to fix, by proposing just to use a subset of the language
    Message 1 of 3 , Oct 28, 2009
    • 0 Attachment
      JSLint helps to use a proper subset of Javascript. Javascript has a lot of issues which JSLint tries to fix, by proposing just to use a subset of the language without loosing any of its functionality.

      So some things are banned: some because they don't work as expected, e.g. the with-statement, some because they have performance penalty, e.g. passing a string instead of a function to setTimeout.

      /\s/("/ /") doesn't add functionality to the language, just another syntax, and its a not very well documented one.

      Actually no one said that: "please do everyone a favor and just forget about it"

      But ask yourself: Does this syntax make your code more clear? Or less?
      And if less: Does it add functionality beyond better documented and wider understood alternatives?





      --- In jslint_com@yahoogroups.com, "robert.luxemburg" <robert.luxemburg@...> wrote:
      >
      > I was playing around with JSLint lately, and entered the following:
      >
      > var ss = " ///// "(" \/ ");
      >
      > JSLint returned: "Problem at line 1 character 10: Bad invocation",
      > and Firebug threw a TypeError, since strings are not callable.
      >
      > So I shuffled these very same characters a bit, until I got:
      >
      > var s = /\s/("/ /"); // " "
      >
      > and JSLint claimed: "Problem at line 1 character 9: Bad invocation",
      > even though the above is, if not valid JS, implemented in Firefox,
      > Safari, Chrome and Opera, as syntactic sugar for /\s/.exec("/ /").
      >
      > See here for a lengthy discussion:
      > https://bugs.webkit.org/show_bug.cgi?id=28117
      >
      > It's definitely an obscure corner case, but shouldn't this be fixed
      > in JSLint? Or added to the corresponding JS Style Guide? "Don't
      > think you can call a RegExp, and if you find out that you actually
      > can, please do everyone a favor and just forget about it..." ?
      >
    • Paul Novitski
      ... May I ask why, if you re supplying the string as a hard-coded literal, are you testing it with a regular expression? Don t you as the scripter already know
      Message 2 of 3 , Oct 28, 2009
      • 0 Attachment
        At 10/27/2009 06:56 PM, robert.luxemburg wrote:
        >var ss = " ///// "(" \/ ");
        >var s = /\s/("/ /"); // " "


        May I ask why, if you're supplying the string as a hard-coded
        literal, are you testing it with a regular expression? Don't you as
        the scripter already know its value?

        I realize that the question "Why would you ever do such a thing?" is
        very different from "Is it legal syntax?" But it is a mystery to my
        why someone would call up the RegExp engine just to find out whether
        a known quoted string contains certain patterns. Is it because the
        string is supplied by a server-side script and not by a human hand?
        Or because you simply enjoy using regular expressions, or exploring
        unusual syntax in your scripts?

        Curiously,

        Paul
        __________________________

        Paul Novitski
        Juniper Webcraft Ltd.
        http://juniperwebcraft.com
      Your message has been successfully submitted and would be delivered to recipients shortly.