IE8 to JS through attribute and array traversal parsing different places to explore _javascript skills

Source: Internet
Author: User
In the text, keep in mind the differences in the browser version of the pits.
Copy Code code as follows:

Array.prototype.Contains = function (str) {
if (!STR)
return false;
for (var i = 0; i < this.length; i++) {
if (this[i] = = str) {
return true;
}
}
return false;
}
var tmp = new Array ();
Tmp.push ("1");
Tmp.push ("2");
Tmp.push ("3");
Alert ("Traversal attribute");
for (var i in TMP) {
Alert (Tmp[i]);
}
Alert ("Traversal array");
for (Var i=0;i<tmp.length;i++) {
Alert (Tmp[i]);
}

If you are a IE8 browser, for example (IE7, IE9, Chrome, FF, test only these types)
The result is the same through attribute and array traversal.
But for IE8, the result will be a little bit different, under IE8 will be the prototype chain extension method as a property output, you can test.

This difference is also due to the resolution of a bizarre bug in which a colleague uses for (Var i in TMP) to traverse each element of the array in the code, and this problem occurs if the prototype chain method is exactly defined for the array.
Therefore, it is recommended that you should use the standard notation for (var i=0;i<tmp.length;i++) If you are traversing an array element.

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.