Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #11731
| From | Tuxedo <tuxedo@mailinator.com> |
|---|---|
| Newsgroups | comp.lang.javascript |
| Subject | Re: Creating a variable named by function parameter? |
| Date | 2012-02-12 19:26 +0100 |
| Organization | albasani.net |
| Message-ID | <jh909f$imr$1@news.albasani.net> (permalink) |
| References | <jh8ost$tsh$1@news.albasani.net> <4f37ec5b$0$6635$9b4e6d93@newsspool2.arcor-online.net> |
Martin Honnen wrote:
[...]
>
> function makeup(x){
> eval('var zebra' + x + ' = document.title;');
> }
> makeup('stripes');
>
> should do but I don't see what you want to achieve with that approach as
> anywhere further on in that function you don't know the name so the only
> way to use it is to do
> eval('zebra' + x)
> again.
Thanks, so the eval steps easily creates a dynamically named variable.
The idea is to proceed to use the newly named variable and its value in
another function, passed on in parameters, something like:
nextFunction('variable_name','the_value')
nextFunction(name,value){
alert(name+'='+value)
}
As the combined variable name became 'zebrastripes' and its value being
whatever the document title is, the function may then return a string like:
zebrastripes=some document title
How can the dynamically created variable name and its value be passed as
two strings onto the nextFunction()? Or even set as a global variable/value
pair which can be accessed in another function?
Many thanks for any additional tips.
Tuxedo
Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Creating a variable named by function parameter? Tuxedo <tuxedo@mailinator.com> - 2012-02-12 17:20 +0100
Re: Creating a variable named by function parameter? Martin Honnen <mahotrash@yahoo.de> - 2012-02-12 17:44 +0100
Re: Creating a variable named by function parameter? Tuxedo <tuxedo@mailinator.com> - 2012-02-12 19:26 +0100
Re: Creating a variable named by function parameter? Tuxedo <tuxedo@mailinator.com> - 2012-02-12 21:47 +0100
Re: Creating a variable named by function parameter? RobG <rgqld@iinet.net.au> - 2012-02-12 18:42 -0800
Re: Creating a variable named by function parameter? Tuxedo <tuxedo@mailinator.com> - 2012-02-13 18:28 +0100
Re: Creating a variable named by function parameter? Robert K Quinlivan <rquinlivan@gmail.com> - 2012-02-13 21:02 -0800
Re: Creating a variable named by function parameter? Tuxedo <tuxedo@mailinator.com> - 2012-02-14 22:55 +0100
csiph-web