Results 1 to 4 of 4

Thread: Object notation question.

  1. #1
    Join Date
    Apr 2008
    Location
    San Diego, CA
    Posts
    352
    Thanks
    57
    Thanked 6 Times in 6 Posts

    Default Object notation question.

    Hi all,

    Is there any difference between:

    Code:
    var object = {
        name : "value"
    };
    and:

    Code:
    var object = {
        "name" : "value"
    };
    ?

    Thanks!

  2. #2
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    Not from what I know.
    Jeremy | jfein.net

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

    Default

    No — but an unquoted name must be a valid identifier.

    Code:
    // These are equivalent:
    ({ foo: 5 });
    ({ 'foo' : 5 });
    
    // But these are legal:
    ({ '1st' : 3 });
    ({ 'class' : 5 });
    ({ 'foo-bar' : 10 });
    // While these are illegal:
    ({ 1st: 3 });
    ({ class: 5 });
    ({ foo-bar: 10 });
    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!

  4. The Following User Says Thank You to Twey For This Useful Post:

    jlizarraga (03-12-2009)

  5. #4
    Join Date
    Jun 2007
    Posts
    543
    Thanks
    3
    Thanked 78 Times in 78 Posts
    Blog Entries
    1

    Default

    Well the first is a more common practice, the second is more like defining array keys: var t=new Array("hi"=>5);, which is actually an object.
    [Jasme Library (Javascript Motion Effects)] My Site
    /\/\@§†ê® §©®¡þ† /\/\@|{ê®
    There are 10 kinds of people in the world, those that understand binary and those that don't.

  6. The Following User Says Thank You to Master_script_maker For This Useful Post:

    jlizarraga (03-12-2009)

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
  •