Javascript 'delete' doesn't work inside iteration loop
<p>I'm a C/C++/Java programmer working with JavaScript.</p>

<p>I'm trying to write a function that will delete all properties of an object 'obj'. I've read the posting on "<a href="http://stackoverflow.com/questions/684575/how-to-quickly-clear-a-javascript-object">How to quickly clear a Javascript Object?</a>" and saw that there are two answers: (1) creating a new 'obj' (which I don't want to do because my code is a high-performance program running in a mobile browser, and I want to minimize garbage collection); and (2) iterating over the properties of an object in a loop and deleting the properties. This latter approach doesn't work in Chrome 12.</p>

<p>Consider the following code:</p>

<pre><code>var foo = {};
foo['baz'] = 'bar';
console.log("1. foo.baz = " + foo.baz);

delete foo.baz;
console.log("2. foo.baz = " + foo.baz);

foo['baz'] = 'bar';
console.log("3. foo.baz = " + foo.baz);

for (prop in foo)
{
    if (foo.hasOwnProperty(prop))
    {
        console.log("deleting property " + prop);
        delete foo.prop;
    }
}
console.log("4. foo.baz = " + foo.baz);
</code></pre>

<p>This produces the following result in my console on Chrome 12:</p>

<pre><code>1. foo.baz = bar
2. foo.baz = undefined
3. foo.baz = bar
deleting property baz
4. foo.baz = bar
</code></pre>

<p>Why doesn't foo.baz get deleted inside the loop?</p>
