Section 12.6.4 explains that for..in
is defined in terms of the following property:
Let P be the name of the next obj property whose [[Enumerable]] attribute is true. If there is no such property, return (normal, V, empty).
Since the concept of βnext propertyβ is well defined even if there is a mutation (although the iterative order is not), delete
does not introduce undefined behavior during iteration.
There is an angular case where delete
does not mask the prototype property, as in
var obj = Object.create({ x: 1 }); obj.y = 2; obj.x = 3; for (var k in obj) { if (k == 'y') { delete obj.x; } alert(k); }
In this case, where you can iterate y
and delete x
, you should still see x
from the prototype, but if you repeated x
first and then y
, you should not see the second x
.
source share