Nested function: am I creating 10 functions here?
<p>I'm working on a function that is too complicated (processor) so I embedded part of the functionality in a nested "utility function" inside it (print). A simplified version of it looks like this:</p>

<pre><code>var out = document.getElementById( "output" );

function processor ( n ) {
    function print( msg ) {
        out.innerHTML  += msg;
    }
    while ( n &gt; 0 ) {
        print( n-- );
        print( ", " );
    }
    print( "&lt;br/&gt;" );
}

for ( var i = 0; i &lt; 10; i++ ) {
    processor( i );
}
</code></pre>

<p>You can see it in action in <a href="http://jsfiddle.net/kVb99/3/" rel="nofollow">this JSfiddle</a>.</p>

<p>The question is: am I really creating 10 instances of the utility function <code>print()</code>? If yes, what is a more efficient way to write this code without putting the utility function outside the <code>processor()</code> function? I want the <code>print()</code> function to only be accessible in <code>processor()</code> and nowhere else. One solution is namespace.</p>

<p>I've read this question and even though it's related but it's not directly my answer:
<a href="http://stackoverflow.com/questions/10709439/efficiency-of-creating-an-event-handler-in-a-nested-loop-am-i-creating-1440-fun">Efficiency of creating an event handler in a nested loop: am I creating 1440 functions here?</a></p>
