title: How to reference properties of current object in JS
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/4616202/self-references-in-object-literal-declarations">Self-references in object literal declarations</a>  </p>
  </blockquote>
  
  
  
  <p>I have some simple objects in JS like this example:</p>
  
  <pre><code>var object = {
   firstname : 'john',
   lastname : 'paul',
   wholename : firstname + lastname
  }
  </code></pre>
  
  <p>Well this simple thing doesn't work; john and paul are undefined in wholename, so I tried to use the 'this' operator which works ONLY if I do a function <code>(getWholeName(){return this.firstname+this.lastname} )</code>.
  But if I want to use a variable and not a function, how can I do? I also tried <code>object.firstname + object.lastname</code> but it doesn't work.</p>