The ie for... in loop has serious defects. In addition to its low performance, many attributes cannot be traversed. The famous three brothers are constructor, tostring, and valueof. But the actual situation is even worse. The following is a test from the Firefox Official Website:Code:
VaR ret = (function () {var OBJ = {constructor: function () {return "0" ;}, tostring: function () {return "1" ;}, valueof: function () {return "2" ;}, tolocalestring: function () {return "3" ;}, prototype: function () {return "4" ;}, isprototypeof: function () {return "5" ;}, propertyisenumerable: function () {return "6" ;}, hasownproperty: function () {return "7" ;}, length: function () {return "8" ;}, unique: function () {return "9" }}; var result = []; for (VAR prop in OBJ) {result. push (OBJ [prop] ();} return result. join ("");})();
<br/> var ret = (function () {<br/> var OBJ = {<br/> constructor: function () {return "0" ;}< br/>, tostring: function () {return "1" ;}< br/>, valueof: function () {return "2" ;}< br/>, tolocalestring: function () {return "3" ;}< br/>, prototype: function () {return "4" ;}< br/>, isprototypeof: function () {return "5" ;}< br/>, propertyisenumerable: function () {return "6" ;}< br/>, hasownproperty: function () {return "7" ;}< br/>, Length: function () {return "8" ;}< br/>, unique: function () {return "9" }< br/>}; </P> <p> var result = []; <br/> for (VAR prop in OBJ) {<br/> result. push (OBJ [prop] (); <br/>}</P> <p> return result. join (""); <br/>}) (); <br/> alert (RET); <br/>
Run code
Result:
IE6 |
IE8 |
Ff3.6 |
Opera10 |
Chrome4 |
Safari4 |
489 |
489 |
0123456789 |
0123456789 |
0123456789 |
0123456789 |