Results 1 to 8 of 8

Thread: Correcting Javascript Console Alert/Errors

  1. #1
    Join Date
    Feb 2006
    Posts
    236
    Thanks
    8
    Thanked 3 Times in 3 Posts

    Default Correcting Javascript Console Alert/Errors

    Hi,

    I was taking a look at the FF browser javascript console to see if there was someting happening in a particularly dense javascript page that could explain a slowness to open and found several alerts. My page is based in part on the DD script at: http://www.dynamicdrive.com/dynamici...menu/index.htm

    So, figuring that these should be corrected so the parser doesn't have to attempt to correct these (and take time to do so), I went to find an online javascript validator, and found one at: http://jslint.com/ and used it with good and bad results. Sure, some of the things obviously needed to be corrected, such as using '!=' instead of the correct '!==' in a comparison, and these changes were ok, and do make things run noticeable faster. But others are not tolerated by FF, like literal notation, where 'var opt=new Array();' is acceptable but 'var opt=new Array[];' is not. And there are others too, such as '{' after an 'else' if on the same line, etc.

    So, what's up and is there a reliable javascript parser, and should I even attempt to apply this to my code since it is expected to run in who-knows-what version of both javascript and JScript (IE)???

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    ECMAScript is the correct term for all the many implementations of ECMA-262, the specification of the latest version of what used to be (and usually still is) called Javascript.
    'var opt=new Array();' is acceptable but 'var opt=new Array[];' is not.
    That's to be expected. Array[] is not acceptable syntax, and will probably be marked as an error and stop parsing (or, worse, be error-corrected and have the parser carry on). I think what the validator would like you to do is 'var opt = [];'. This would be valid, but, insofar as I can tell, would offer no advantage over 'new Array()' other than saving some typing.
    And there are others too, such as '{' after an 'else' if on the same line, etc.
    Syntactically, there is no problem with this, since extraneous white-space (or lack thereof) is totally ignored except after a statement, where a linebreak can cause the insertion of a semicolon by the ECMAScript parser.

    I would totally ignore the output of that verifier. It has issues with things that would cause no problems at all, such as missing out optional arguments to functions. Some of the things it says are OK, but they are all things an experienced script-writer would probably catch anyway, and it tends to attempt to force a certain style of coding on you where it has no need to be; for example, omitting braces from before single-line conditionally-executed statements. Certainly not the best tool to check your scripts with, especially if you're new and can't tell the difference between what's really a problem and what isn't.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  3. #3
    Join Date
    Feb 2006
    Posts
    236
    Thanks
    8
    Thanked 3 Times in 3 Posts

    Default

    Well, I suspected as much from that validator. Still, I was interested in removing the java console's 'deprecated arguments usage' concerns, figuring that sooner or later I would find they were a problem. And I still don't know what the parser was looking at (no line number given).

    Is there a validator that works realistically?

  4. #4
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    The Java console? I thought we were discussing ECMAScript?
    Is there a validator that works realistically?
    Not to my knowledge. Just test it in a few browsers.
    'deprecated arguments usage'
    Won't be a problem now, but may become one in the future. If you give an URL, I'll have a look. You must be doing something pretty unusual; I've never seen FX throw one of these.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  5. #5
    Join Date
    Aug 2005
    Posts
    971
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Well to tell you the truth there is a validator out there. visit http://jslint.com/

  6. #6
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    I have nothing to say to that.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  7. #7
    Join Date
    Aug 2005
    Posts
    971
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by Twey
    I have nothing to say to that.
    huh?? didn't get it!! Did I say something wrong??

    If so then sorry!

  8. #8
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Would you like to make some pretense at reading the thread before posting?
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •