easysoft / zui

ZUI is an HTML5 front UI framework.
https://openzui.com
MIT License
2.71k stars 690 forks source link

关于 ie8 兼容性问题 - indexOf 和 forEach #171

Closed peppermit closed 4 years ago

peppermit commented 4 years ago

测试 ie8 兼容性时,发现没有对 indexOf 和 forEach 这两个方法进行处理。 建议加上以下两段代码

if(!Array.prototype.indexOf) {
    Array.prototype.indexOf = function(elt /*, from*/ ) {
        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;
    };
}

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++;
        }
    };
}
catouse commented 4 years ago

谢谢反馈,不过我们的标准版 JS 代码中没有用到这两个方法。如果有用到欢迎指出。

catouse commented 4 years ago

lib/array 下有 Polyfill,可以针对 IE8 导入使用。