Scope of JavaScript Objects
<p>Quick question about JSON in general, say I had:</p>

<pre><code>var foo = {
  a: null,
  init: function() {
    this.a = document.getElementById(...);
  }
}
</code></pre>

<p>This will give have a with null. Is there anyway to go outside this scope and get the document element other than doing it externally via foo.a = document.getElementById(...)?</p>

<p>EDIT: Changed title more appropriately.</p>

<p>I am calling foo.init(), but when I do this, say I have:</p>



<p>and then I call init.foo() which contains this.a = document.getElementById('test') it seems to return NULL, perhaps I am doing something wrong.</p>
