title: What is the best way to define dependent variables in an object?
body: <p>In the <a href="https://developers.google.com/speed/articles/optimizing-javascript" rel="nofollow noreferrer">Google developers recommendation</a> for optimizing JavaScript code, they mention that the best way to declare/initialize new variables for object is to use the prototype. For instance, instead of:</p>
  <pre><code>foo.Bar = function() {
      this.prop1_ = 4;
      this.prop2_ = true;
      this.prop3_ = [];
      this.prop4_ = 'blah';
  };
  </code></pre>
  <p>Use:</p>
  <pre><code>foo.Bar = function() {
      this.prop3_ = [];
  };
  
  foo.Bar.prototype.prop1_ = 4;
  foo.Bar.prototype.prop2_ = true;
  foo.Bar.prototype.prop4_ = 'blah';
  </code></pre>
  <p>However, in my case I have a dependency between variables, for instance:</p>
  <pre><code>var appv2 = function(){
      this.start(this.person, this.car); 
  }; 
  
  appv2.prototype.toWhom = 'Mohamed'; 
  appv2.prototype.person = new person(this.toWhom); 
  appv2.prototype.car = new car();
  
  appv2.prototype.start = function(person, car){
      console.log('start for appv2 is called'); 
      person.sayHello('me app v2');
      car.brand();    
  }; 
  
  new appv2(); 
  </code></pre>
  <p>Using <code>this.toWhom</code> outside of the main constructor body or a method function of the object will yield undefined. To solve this I could use <code>appv2.prototype.toWhom</code> instead of <code>this.toWhom</code> or I could declare my dependent variables inside of the main constructor body.</p>
  <p>But I would like to know what is the best way, in terms of performance, to accomplish this?</p>
  <p>Thanks</p>