How does javascript solve IE8 does not support forEach ()

Source: Internet
Author: User
ForEach is added to the ECMA-262 standard in version 5, which does not support forEach () for IE 8 or earlier versions (). this article explains how to solve the problem that IE8 does not support forEach (). For more information about coders, see. forEachIs added to the ECMA-262 standard in version 5; so it may not exist in other implementations of the standard, you can call forEachInsert the following code and use it if it is not supported locally. forEach(). The algorithm is specified in ECMA-262 5th. Algorithm hypothesis ObjectAnd TypeErrorHas their initial values. callback.callEquivalent Function.prototype.call().

if ( !Array.prototype.forEach ) {  Array.prototype.forEach = function forEach( callback, thisArg ) {    var T, k;    if ( this == null ) {      throw new TypeError( "this is null or not defined" );    }    var O = Object(this);    var len = O.length >>> 0;     if ( typeof callback !== "function" ) {      throw new TypeError( callback + " is not a function" );    }    if ( arguments.length > 1 ) {      T = thisArg;    }    k = 0;    while( k < len ) {      var kValue;      if ( k in O ) {        kValue = O[ k ];        callback.call( T, kValue, k, O );      }      k++;    }  };}

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.