Self executing function and the document.write
<p>I have this self-executing function:</p>

<pre><code>&lt;script type="text/javascript"&gt;
(function() {
var sc      = document.createElement('script'); 
    sc.src   = 'http://blahblah.com/test.js';
    sc.type = 'text/javascript'; 

var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(sc, s);
})();
&lt;/script&gt;
</code></pre>

<p>All that is contained in test.js is:</p>

<pre><code>document.write('ping!');
</code></pre>

<p>However, it hangs -- am I doing something incorrect?</p>

<p>I found a way to go around the document.write but now the only question is why does this not work. </p>

<pre><code>var nc = document.createElement('div');  
nc.appendChild(document.createTextNode('blah'));  
var scr = document.getElementsByTagName('script')[0];  
scr.parentNode.insertBefore(nc, scr);  
</code></pre>
