Referencing an object property dynamically

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Andrew Poulos

    Referencing an object property dynamically

    If I create a number of objects, obj0, obj1, obj2,... and they each have
    a property assigned (so I could reference, say, obj0.foo) how can I
    reference it when it is dynamically built? For example, with

    var tmp = 0;

    the following all fail:

    myFunction( obj+tmp.foo );
    myFunction( "obj"+tmp.f oo );
    myFunction( ["obj"+tmp].foo );
    myFunction( ["obj"+tmp]foo );

    var k = "obj"+tmp;
    myFunction( k.foo );

    var k = ["obj"+tmp];
    myFunction( k.foo );


    Andrew Poulos
  • Michael Winter

    #2
    Re: Referencing an object property dynamically

    On Thu, 23 Dec 2004 12:40:50 +1100, Andrew Poulos <ap_prog@hotmai l.com>
    wrote:
    [color=blue]
    > If I create a number of objects, obj0, obj1, obj2,... and they each have
    > a property assigned (so I could reference, say, obj0.foo) how can I
    > reference it when it is dynamically built?[/color]

    [snip]

    This is covered in the FAQ notes
    (<URL:http://www.jibbering.c om/faq/faq_notes/faq_notes.html> ) article
    regarding bracket notation.

    Mike

    --
    Michael Winter
    Replace ".invalid" with ".uk" to reply by e-mail.

    Comment

    Working...