forEach函数自定义

IE9以下没有forEach,可以自己加个,代码如下:

if (!Array.prototype.forEach)  
{  
    Array.prototype.forEach = function(fun /*, thisp*/)  
    {  
        var len = this.length;  
        if (typeof fun != "function")  
            throw new TypeError();  
  
        var thisp = arguments[1];  
        for (var i = 0; i < len; i++)  
        {  
            if (i in this)  
                fun.call(thisp, this[i], i, this);  
        }  
    };  
} 

 

posted @ 2014-05-12 15:46  iRex  阅读(181)  评论(0)    收藏  举报