how javascript framework have own workspace?
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/7719189/javascript-create-incode-workspace-framework">javascript create INcode workspace (framework)</a>  </p>
</blockquote>



<p>In the last few days i have been interesting in how Javascript framework have they own workspace , what i mean is how they can call a variable at any name they want and work with it without involving local variables.</p>

<p>I'm writing now an API and i'm facing the problem of the local variables / function local names , if they already exist.</p>

<p>So , what i have done is looking into how framework works and i saw they use namespace functions like this :</p>

<pre><code>(function(){ .... })()
</code></pre>

<p>so i tried to do something alike</p>

<pre><code>&lt;html&gt;

  &lt;head&gt;
    &lt;script type="text/javascript"&gt;
      (function() {
        function f(toAlert) {  alert(toAlert);  }
      })();
    &lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;

    &lt;script&gt;
      toAlert("hi");
    &lt;/script&gt;

  &lt;/body&gt;
&lt;/html&gt;
</code></pre>

<p>but it's not working..</p>

<p>so i have few questions :</p>

<ol>
<li><p>how to have a workspace in javascript to set any variable name i want (if function too it would be great).</p></li>
<li><p>i saw that the frameworks uses "window" command , is it have something to do with the namespace function to "public" the function or w/e?</p></li>
<li><p>i'll be glad if you can give me information / tutorials about all this thing , how to make it done from beginning to ending </p></li>
</ol>
