Javascript parser

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Csaba2000

    #16
    Re: Javascript parser

    "Douglas Crockford" <nospam@covad.n et> wrote in message
    news:62432$422b 3e69$436564ee$2 5426@msgid.mega newsservers.com ...[color=blue]
    >
    > 10000 might be a bit of a download. JSLINT now lists all member names.
    > Please try it. Let me know if it is useful, or if more is required.
    >
    > http://www.crockford.com/javascript/jslint.html[/color]

    Despite my post length, I'm actually not very opinionated on the matter.
    But I did go check it out, and it failed on this small piece of web page:

    <html><body onLoad="tryit() " id=myBody>
    <script type='text/javascript'>
    // just say no to long function names
    // elem = document.getEle mentById; // didn't work on Firefox
    var elem = function (myId) {return document.getEle mentById(myId); }
    function tryit() {alert (elem('myBody') .id);}
    </script></body></html>

    It didn't like that there was no semicolon after the function
    (on the var elem line). I put the ';' in and then it passed, but
    I thought in case you hadn't run across this type of construct,
    you might want to know.

    Also, perhaps I don't get something. When I changed capitalization
    on .getElementById , then Members listed the new capitalization
    but I thought it would be in red or something to alert me to a
    capitalization discrepency. Did I miss something?

    Regards,
    Csaba


    Comment

    • Michael Winter

      #17
      Re: Javascript parser

      Csaba2000 wrote:

      [snip]
      [color=blue]
      > It didn't like that there was no semicolon after the function (on
      > the var elem line). I put the ';' in and then it passed, but I
      > thought in case you hadn't run across this type of construct, you
      > might want to know.[/color]

      JSLint is correct. You would expect a semicolon after

      var num = 6

      A function expression is just like any other expression in this regard.

      Notice that a function expression is completely different from a
      function declaration. This:

      function myFunction() {
      /* ... */
      } /* <-- No semicolon */

      is proper. This:

      var myFunction = function() {
      /* ... */
      } /* <-- No semicolon */

      isn't.
      [color=blue]
      > When I changed capitalization on .getElementById , then Members
      > listed the new capitalization but I thought it would be in red or
      > something to alert me to a capitalization discrepency. Did I miss
      > something?[/color]

      The change was to list all members encountered in code and the number
      of times each individual member was found. The idea is that if you use
      a member a couple of times, but type it incorrectly, you'll see more
      than one listing.

      As Douglas pointed out, what counts as "standard" method names will
      vary from platform-to-platform, so it isn't really feasible to
      generate a list. A programmer is free to create any properties
      desired, with any form of capitialisation . There is nothing (other
      than common sense :D) stopping someone creating a GetElementByID
      method on the document object, so how could a simple automated tool
      assert that this is incorrect?

      Mike

      --
      Michael Winter
      Replace ".invalid" with ".uk" to reply by e-mail.

      Comment

      • Ira Baxter

        #18
        Re: Javascript parser


        "Jeff Robichaud" <jfrobichaud@gm ail.com> wrote in message
        news:qh2Wd.9285 4$vO1.579579@nn rp1.uunet.ca...[color=blue]
        > Hi, I would like to know if there exists a tool that one can use to test
        > some javascript code before actually running it ? Something that would[/color]
        check[color=blue]
        > the syntax at least ? I found that most mistakes that I make when coding[/color]
        in[color=blue]
        > javascript are syntax-related.[/color]

        See our JavaScript formatter. It parses and reformats, too.




        --
        Ira D. Baxter, Ph.D., CTO 512-250-1018
        Semantic Designs, Inc. www.semdesigns.com


        Comment

        Working...