扩展js添加each 迭代方法

来源:互联网 发布:三坐标编程教材 编辑:程序博客网 时间:2024/04/30 01:10
Array.prototype.each = function (fn) {    try {        this.i || (this.i = 0);        if (this.length > 0 && fn.constructor === Function) {            while (this.i < this.length) {                var item = this[this.i];                if (e && this.constructor === Array) {                    e.each(fn);                } else {                    //fn(item);                    fn.apply(item, [item]);                }                this.i++;            }            this.i = null;        }    } catch (e) {    }    return this;};
0 0
原创粉丝点击