On limiting JavaScript global variables
<p>I am reading a book that encourages the reader for a few reasons, to limit global variables. The technique they recommend is to define a global object variable, like the following:</p>

<pre><code>var myapp = {}; 

var myapp.another_stooge = { 
  'first-name': 'Lenny',
  'last-name': 'George'
};

var myapp.properties = [ 
  'first-name',
  'last-name'
  ];  

for (i = 0; i &lt; myapp.properties.length; i += 1) {
  document.writeln(myapp.properties[i] + ': ' + 
  myapp.another_stooge[myapp.properties[i]] + 
 '&lt;BR/&gt;');
}
</code></pre>

<p>This does not write to my html file, but implemented without using myapp, it works:</p>

<pre><code>var another_stooge = {
  'first-name': 'Lenny',
  'last-name': 'George'
};

var properties = [
  'first-name',
  'last-name'
];  

for (i = 0; i &lt; properties.length; i += 1) {
  document.writeln(properties[i] + ': ' + another_stooge[properties[i]] + '&lt;BR/&gt;');
}
</code></pre>

<p>I must be missing something simple but could not catch it; any direction would be appreciated. Thank you!</p>
