SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    padawan silver trophybronze trophy markbrown4's Avatar
    Join Date
    Jul 2006
    Location
    Victoria, Australia
    Posts
    4,122
    Mentioned
    29 Post(s)
    Tagged
    2 Thread(s)

    object properties with array syntax

    Hi,

    I asked the question in a recent post - which didn't get any responses - maybe the question was too big.
    One part was asking about how to add extra properties to html elements as I was storing data in html attributes.

    After looking at some others code including Raphael and this addEvent code.
    http://www.quirksmode.org/blog/archi..._winner_1.html

    They seem to treat objects just like an array.
    obj[property] = value;

    This would have been extremely helpful to know previously as I have needed to be able to include variables in property names - but have resorted to making the whole thing a string and calling exec() on it.

    Are there any problems with using this syntax?

  2. #2
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Using the brackets is pretty common actually. You can kinda use objects like an associative array/hash map that way, although you need to beware of possible additions to Object.prototype

  3. #3
    padawan silver trophybronze trophy markbrown4's Avatar
    Join Date
    Jul 2006
    Location
    Victoria, Australia
    Posts
    4,122
    Mentioned
    29 Post(s)
    Tagged
    2 Thread(s)
    object/array syntax, where have you been all my life?


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
  •