JavaScript some functions not supported under IE summary

Source: Internet
Author: User

    // ============   isarray  ===============//                  //  isarray       function  IsArray (value) {          return Object.prototype.toString.call (value) = = "[Object] Array] ";      }       var arr = [1,2,3,4,5];       // IE8 and below are not  supported

  //============ Filter and other ===============//    //Some methods of array every (), filter (), ForEach (), map (), some ()    //IE8 and below are not supported    //solution, take filter as an example and write a filter    if(!Array.prototype.filter) {Array.prototype.filter=function(Fun/*, Thisp*/){              varLen = This. Length; if(typeofFun! = "function"){                  Throw NewTypeError (); }              varres =NewArray (); varThisp = arguments[1];  for(vari = 0; i < Len; i++){                  if(Iinch  This){                      varval = This[i];//In case fun mutates this                    if(Fun.call (Thisp, Val, I, This) {Res.push (val); }                  }              }              returnRes;      }; }            varnumbers = [1,2,3,4,5,6]; varFilterresult = Numbers.filter (function(item, Inde, array) {return(item>2);      }); alert (Filterresult); //3,4,5,6

        //  ============   Date.now ()  ===============//       //  date.now (); IE8 and below do not support, can only write a  solution    if(! ) Date.now) {          function() {              returnnew  Date (). ValueOf ();          }      }      Alert (Date.now ());        

 //  ============ stringvalue[1] ============    ===// //  show IE7 in undefined and the following versions       var  stringvalue = "Hello World" ;        Alert (stringvalue[ 1   
        // ============   trim ()  ===============//      //  in IE8 and the following versions are invalid and need     to be written by yourself    function() {          returnthis. Replace (/(^\s*) (\s*$)/g, "") ;      };             var stringValue2 = "   Hello world  ";      Alert (Stringvalue2.trim ());  

JavaScript some functions not supported under IE summary

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.