www.webdeveloper.com
Results 1 to 3 of 3

Thread: [RESOLVED] How to reference object properties?

  1. #1
    Join Date
    Sep 2009
    Posts
    2

    resolved [RESOLVED] How to reference object properties?

    I'm trying to develop a calculator to help make cost estimates for leaflets. Depending on paper format I want different factors to apply when the calculation is done. The formats have one letter (A, B or C) and one number (from 0 to 10). Another function has found the correct format and stored the result in two variabels (x and y in the example below). What I would like to do is concatenate these two variables so that I can get to the right object instance and retrieve the factors but this won't work. Javascript returns undefined and not 1 as was intended.


    function format(fFactor, pFactor) {
    this.fFactor = fFactor;
    this.pFactor = pFactor;
    }

    var A4 = new format(1, 1);
    var A3 = new format(1, 2);
    var A2 = new format(2, 4);

    var x = "A";
    var y = 4;
    var z = (x + y);

    document.writeln(z.fFactor);

  2. #2
    Join Date
    Jun 2007
    Posts
    667
    Quote Originally Posted by bleu View Post
    What I would like to do is concatenate these two variables so that I can get to the right object instance
    Use this[z].fFactor or since its in the global scope window[z].fFactor
    Y_U U_G_A_E_U_ B_S_A_D_

  3. #3
    Join Date
    Sep 2009
    Posts
    2
    Amazing, it worked. Thanks a lot!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles