Javascript Namespace Help
<p>I have a pretty big Javascript script with loads of global variables &amp; functions in it. Then a piece of code that calls one function from this js file: myfunc();</p>

<p>Ok, now I have cloned this script and modified some functionality, all function prototypes and variables are named the same in both scripts. So now I have two scripts loaded and one call to myfunc(), now we have a clash because there are loads of global variables with the same names and two myfunc()s.</p>

<p>What I want to do is wrap this cloned script in a namespace, so that I can modify the original call to: clone.myfunc() which will call the new function, but I also want myfunc() to just refer to the original script. In other words I can't touch the original script (no permissions) and I want to be able to use both the clone and the original at runtime.</p>

<p>This is the script im cloning: <a href="http://pastebin.com/6KR5T3Ah" rel="nofollow">http://pastebin.com/6KR5T3Ah</a></p>

<p>Javascript namespaces seem quite tricky this seems a nice namespace method:</p>

<pre><code>var namespace = {
    foo: function() {
    }

    bar: function() {
    }
}

...

namespace.foo();
}
</code></pre>

<p>However that requires using an object, and the script (as posted above) is humongous at nearly 4000 lines, too much to objectize I think?</p>

<p>Anyone know a better solution to avoid namespace pollution, with one script I cant touch and one being a clone of that script. Just so I can call myfunc() and clone.myfunc() and all global variables will behave in their respected scope.</p>

<p>It's either that, or I go through and modify everything to have unique names, which may take a lifetime</p>

<p>This is a Mozilla addon if it helps context wise.</p>

<p>Thanks.</p>
