Page 2 of 3 FirstFirst 123 LastLast
Results 11 to 20 of 22

Thread: [JAVASCRIPT] Javascript Serialize

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

    Default

    what does the "final" keyword signify?
    In Java, it signifies a constant. In Javascript, nothing yet (as far as I know), but the ECMAScript standard defines it as being "reserved for future use."

    /EDIT: My error, array_push() wasn't doing what I thought it was. The expected output is actually:
    Code:
    a:1:{i:0;a:1:{i:0;N;}}
    Last edited by Twey; 01-07-2007 at 06:07 PM.
    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!

  2. #12
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    Quote Originally Posted by Twey
    but the ECMAScript standard defines it as being "reserved for future use."
    So it doesn't initiate the statement right away? I'm really new to the final variable name, so I'm probably wrong.
    - Mike

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

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

    Default

    So it doesn't initiate the statement right away? I'm really new to the final variable name, so I'm probably wrong.
    No, it means it doesn't do anything at all, but might do later if Ecma get around to it
    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. #15
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    Yeah, I've fiddled around with ECMA script a little bit myself, and as far as I know, it works exactly like JavaScript, except with add-ons.
    - Mike

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

    Default

    ECMAScript is the standard to which JavaScript, JScript, ActionScript, and a few others conform.
    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. #17
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    To grasp what is going on with the 'final' keyword or whatever you want to call it in javascript, consider the history of the 'try' keyword. I think that this bit of reserving words is poorly thought out but, in javascript we now have the:

    Code:
    try{
    
    }
    catch(e){
    
    }
    finally {
    
    }
    construct. There was a time when we did not but, in browsers written before this construct became a part of the standard, all legitimate uses of try will cause a script to abort. That is because 'try' was reserved prior to its use in the above construct. They should have just left 'try' out of consideration entirely so that it could be tested for as an available method without causing older browsers to barf. The same (it appears) is true of 'final' except that nothing has been assigned to it yet, making all browsers 'older browsers' when it comes to its use as a variable. Stupid, if you ask me.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

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

    Default

    ... it could be tested for as an available method without causing older browsers to barf.
    How?

    It's virtually impossible to test for a keyword, since the browsers that do recognise it will barf if it's used as an identifier anyway. About the only way of doing it is using try/catch with eval(), whose exceptions are not always fatal:
    Code:
    try {
      eval("var final;");
    } catch(e) {
      // final is reserved (and thus implemented)
    }
    However, since it's reserved without being implemented in the current state of affairs, we do the test the other way around:
    Code:
    try {
      eval("final myvar;");
    } catch(e) {
      // We can't define final variables (so final isn't implemented).
    }
    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!

  9. #19
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    I think you just answered your own question. There should be a better way, I agree. Ever since I found out about it, quite some time ago, I've always liked the 'typeof' construct. It should be able to be used in these instances but, as far as I know, it cannot.

    Just as a footnote to the problems with 'try' - if you are determined to use it in code that you also want to be able to degrade gracefully to older browsers, there are established but somewhat elaborate and questionable (from the point of view of full future compatibility) ways of doing so. These involve using the archaic language attribute for alternate script blocks as well as filtering IE versions with conditional comments as, IE doesn't respect the language attribute conventions in place during the evolution of the use of 'try'. A real mess, if you ask me. In the end not even 100% but, very near so with existing browsers.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  10. #20
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    Quote Originally Posted by jscheuer1
    I've always liked the 'typeof' construct
    That tells you what type of data (variable name: boolean, integer, string, etc.) in the variable, not the type of keyword. Well, as far as I know.
    - Mike

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
  •