Namespaces in JavaScript: do I need to rewrite all my variable and function references?
<p>I am namespacing some JavaScript code, and I want to know if I have rewritten all my function calls and references to global variables correctly. The current code is this: </p>

<pre><code>var x = 10;
function foo() {
    console.log('foo');
    bar();
  },
function bar() {
  console.log('bar', x);
}  
foo();
</code></pre>

<p>I have rewritten it as follows: </p>

<pre><code>var namespace = {  
  x : 10,
  foo: function() {
    console.log('foo');
    // Is this the correct way to call bar?
    this.bar();
  },
  bar: function() {
    // Is this the correct way to refer to x?  
    console.log('bar', this.x);
  }  
};
namespace.foo();
</code></pre>

<p>Is this correct, i.e. do I need to rewrite all function calls (EDIT: by which I mean all inside the namespace variable) to <code>this.functionname()</code> and all global variables to <code>this.variablename</code>? </p>
