Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    May 2006
    Posts
    27
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Defining variable names at runtime..

    Hi, does anybody know whether it's possible to create variable names at runtime.

    For example

    DEFINE? ('bob')

    would create a variable named 'bob'.

    I played around with eval for a while, but didn't get very far...

    Thanks...

  • #2
    Senior Coder
    Join Date
    Mar 2005
    Location
    Portsmouth UK
    Posts
    4,494
    Thanks
    3
    Thanked 500 Times in 487 Posts
    window['auniquestring']='anyoldvalue'
    Vic

    God Loves You and will never love you less.

    http://www.vicsjavascripts.org/Home.htm

    If my post has been useful please donate to http://www.operationsmile.org.uk/

  • #3
    Senior Coder
    Join Date
    Jul 2005
    Location
    New York, NY
    Posts
    1,084
    Thanks
    4
    Thanked 19 Times in 19 Posts
    There is only runtime in javascript.

    There are no constants, macros, or preprocessor symbols.

    So what vwphillips just recommended is a way of creating a global variable. You must allocate memory for it, no way around it.

    Also to clarify, you can then use the above example like so:

    alert(auniquestring);


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •