Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #11764

Re: Creating a variable named by function parameter?

From Tuxedo <tuxedo@mailinator.com>
Newsgroups comp.lang.javascript
Subject Re: Creating a variable named by function parameter?
Date 2012-02-14 22:55 +0100
Organization albasani.net
Message-ID <jhel8g$pu6$1@news.albasani.net> (permalink)
References <jh8ost$tsh$1@news.albasani.net> <7f857d68-a9aa-40dd-9944-d573dd41f71e@m7g2000vbw.googlegroups.com>

Show all headers | View raw


Robert K Quinlivan wrote:

[...]

> There's eval, but eval is bad. Very bad. Possibly the worst feature of
> any programming language is the ability to execute totally arbitrary
> code.
> 
> Do this instead:
> 
> var zebra = {};
> 
> function makeup(x) {
> zebra[x] = document.title;
> }
> 
> makeup('stripes');
> 
> Basically, don't do what you were planning to do. It violates several
> principles of good program design.

The partial variable (or object) name with the empty curly braces and 
function variable name completion works great!

As you say, I guess it's better than using eval.

Thanks for this tip.

Tuxedo

Back to comp.lang.javascript | Previous | Next — Previous in thread | Find similar | Unroll thread


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