I just encountered some really weird behaviour with MochiKit.Iter - Is
this expected behaviour, or a bug?
<html>
<head>
<title>forEach vs getElementsByTagName</title>
<script type="text/javascript" src="res/mochikit.js"></script>
</head>
<body>
<div id="container">
<span> </span>
<span> </span>
<span> </span>
<span> </span>
<span> </span>
<span> </span>
<span> </span>
<span> </span>
</div>
<script type="text/javascript">
var container = $("container");
var it = container.getElementsByTagName("span");
var len1 = it.length;
var len2 = 0;
forEach(container.getElementsByTagName("span"), function(span) {
span.parentNode.removeChild(span);
len2++;
});
alert("length 1 = " + len1 + "\n" + "length 2 = " + len2 + "\n");
</script>
</body>
</html>
Expected output is 8 in both cases, but only the first method does
that. Using forEach, I get only 4. This clearly has something to do
with the fact that I'm manipulating the DOM inside the callback, but I
would have expected an iterator to be immutable ?!?
--
troels
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"MochiKit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/mochikit?hl=en
-~----------~----~----~----~------~----~------~--~---