Create a private namespace independent of other javascript?
<p>I am creating a script which may be used on a variety of websites. Since I don't know the circumstances of it's use, I'd like to be able to place it in a sandbox of sorts, where it does not affect other javascripts on the page, and is in turn not effected by other javascripts.</p>

<p>The most basic start is using a self-invoking function:</p>

<pre><code>(function(){
   x = function(){ alert('hi!');
   x();
})();
</code></pre>

<p>But my problem is that if x is already assigned as such, you cannot override it:</p>

<pre><code>x = function(){ alert('too late!');
(function(){
   x = function(){ alert('hi!');
   x();
})();
</code></pre>

<p>This will alert "too late!" rather than "hi!", which is not my desired effect. Can anyone help?</p>
