SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot
    Join Date
    Aug 2011
    Location
    Trinidad and Tobago
    Posts
    194
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    What does {foo: "bar"} mean

    when dealing with javascript what does this mean {foo: "bar"} in terms of a function as an object?

  2. #2
    SitePoint Guru
    Join Date
    Apr 2006
    Posts
    802
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you ever have need of the word 'bar',
    instead of typing 'bar' out, one letter at a time,
    you can read the foo property of the object you created-

    calling mynewobject.foo, returns 'bar'.

  3. #3
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,719
    Mentioned
    103 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by skelleex View Post
    when dealing with javascript what does this mean {foo: "bar"} in terms of a function as an object?
    It creates an object that contains one property. That property has a key name of foo, and that key called foo contains a vaue of "bar"

    If you assign the object to a variable, such as baz, you can retrieve the property value by using either array-index notation, or by accessing the appropriate property of that object.

    Code javascript:
    var baz = {foo: "bar"};
    var valueFromArrayIndex = baz[foo];
    var valueFromProperty = baz.foo;
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript


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
  •