How to call a self executing function in JavaScript?
<p>When I have some code I need to execute more than once I wrap it up in a function so I don't have to repeat myself. Sometimes in addition there's a need to execute this code initially on page load. Right now I do it this way:</p>

<pre><code>function foo() {
   alert('hello');
}

foo();
</code></pre>

<p>I would rather do it this way:</p>

<pre><code>(function foo() {
   alert('hello');
})();
</code></pre>

<p>Problem is, this will only execute on page load but if I try to call it subsequent times using <code>foo()</code> it won't work.</p>

<p>I'm guessing this is a scope issue but is there any way to get self executing functions to work upon getting called later?</p>
