Prototype Assignment functions...

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • PhoenixCode
    New Member
    • Jan 2008
    • 1

    Prototype Assignment functions...

    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:
    Code:
    Q("a","blah");
    
    // or a.Q("blah");
    // to assign the value of "blah" to the variable a
    
    alert(a); // -----> returns "blah"
    Example 2:

    Code:
    Q("x",123 + 456);
    
    // or x.Q(123+456)
    // to assign the value of the sum of 123 + 456 to the variable x
    
    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:

    Code:
    a = "blah";
    and

    Code:
    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
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    How about:
    [code=javascript]function Q(variable, value) {
    window[variable] = value;
    }[/code]

    Comment

    Working...