Javascript delete mechanics
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/6173308/the-delete-operator-in-javascript">the delete operator in javascript</a>  </p>
</blockquote>



<p>I have the following code. I don't understand why the second delete fails.</p>

<p>Also, I noticed that the foo function still exists even after I assigned something else to foo.</p>

<p>Is there a way to reference the function?<br>
(suppose I'd want a <code>bar2=foo()</code> to behave like the <code>bar</code> assignment).</p>

<pre><code>&gt; function foo(){var bar=0; return function(){return bar++;}}
undefined
&gt; bar = foo()
function () {return bar++;}
&gt; bar()
0
&gt; bar()
1
&gt; delete bar
true
&gt; foo = foo()
function () {return bar++;}
&gt; foo()
0
&gt; foo()
1
&gt; delete foo
false
</code></pre>

<p>Thanks</p>
