示曲豆
------ 千礼之行始于足下。。

今天在测试IE8的时候,遇到数组不支持indexOf的问题,在使用indexOf 方法前,对Array的原型方法进行扩展。

if (!Array.prototype.indexOf)
    {
        Array.prototype.indexOf = function(elt)
        {
            var len = this.length >>> 0;

            var from = Number(arguments[1]) || 0;
            from = (from < 0)
                ? Math.ceil(from)
                : Math.floor(from);
            if (from < 0)
                from += len;

            for (; from < len; from++)
            {
                if (from in this &&
                    this[from] === elt)
                    return from;
            }
            return -1;
        };
    }

 

posted on 2014-09-29 18:11  示曲豆  阅读(207)  评论(0编辑  收藏  举报