By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,914 Members | 1,100 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,914 IT Pros & Developers. It's quick & easy.

Prototype Assignment functions...

P: 1
I'm in the process of simplifying my code and I want to find out how feasible it is to do the following...

Example 1:
Expand|Select|Wrap|Line Numbers
  1. Q("a","blah");
  2.  
  3. // or a.Q("blah");
  4. // to assign the value of "blah" to the variable a
  5.  
  6. alert(a); // -----> returns "blah"
Example 2:

Expand|Select|Wrap|Line Numbers
  1. Q("x",123 + 456);
  2.  
  3. // or x.Q(123+456)
  4. // to assign the value of the sum of 123 + 456 to the variable x
  5.  
  6. alert(x); // -----> returns 579
Anybody have any idea how to go about creating a function that could do that?

Please don't question why I want to do this, I want to know if it's possible and how... and please don't provide me with answers like:

Expand|Select|Wrap|Line Numbers
  1. a = "blah";
and

Expand|Select|Wrap|Line Numbers
  1. x = 123 + 456;
Just humor me... this is something I want to try, so I want to know how possible it is to do this sort of thing...

Thanks...

-- Fibonacci Jones
Jan 24 '08 #1
Share this Question
Share on Google+
1 Reply


acoder
Expert Mod 15k+
P: 16,027
How about:
Expand|Select|Wrap|Line Numbers
  1. function Q(variable, value) {
  2.   window[variable] = value;
  3. }
Jan 24 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.