Properties that cannot be traversed in IE

Source: Internet
Author: User
Tags hasownproperty

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
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.