SoFunction
Updated on 2025-04-10

Introduction to the new features of JavaScript 1.6 arrays and several tools and methods of JQuery


-function(){

function applyIf(o, c) {
    if(o) {
        for(var p in c) {
            if(o[p]===undefined) {
                o[p] = c[p];
            }
        }
    }
    return o;
}
applyIf(, {
    indexOf : function(obj, idx) {
        var from = idx == null ? 0 : (idx < 0 ? (0, + idx) : idx);
        for(var i = from, l = ; i < l; i++) {
            if(i in this && this[i] === obj) {
                return i;
            }
        }
        return -1;
    },
    lastIndexOf : function(obj, idx) {
        var len = , from = idx == null ? len - 1 : idx;
        if(from < 0) {
            from = (0, len + from);
        }
        for(var i = from; i >= 0; i--) {
            if (i in this && this[i] === obj) {
                return i;
            }
        }
        return -1;
    },
    every : function(fn, thisObj) {
        var l = ;
        for(var i = 0; i < l; i++) {
            if(i in this && !(thisObj, this[i], i, this)) {
                return false;
            }
        }
        return true;
    },
    some : function(fn, thisObj) {
        var l = ;
        for(var i = 0; i < l; i++) {
            if(i in this && (thisObj, this[i], i, this)) {
                return true;
            }
        }
        return false;
    },
    filter : function(fn, thisObj) {
        var l = , res = [], resLength = 0;
        for(var i = 0; i < l; i++) {
            if(i in this) {
                var val = this[i];
                if((thisObj, val, i, this)) {
                    res[resLength++] = val;
                }
            }
        }
        return res;
    },
    map : function(fn, thisObj) {
        var l = , res = [];
        for(var i = 0; i < l; i++) {
            if(i in this) {
                res[i] = (thisObj, this[i], i, this);
            }
        }
        return res;
    },
    forEach : function(fn, thisObj) {
        var l = ;
        for(var i = 0; i < l; i++) {
            if(i in this) {
                (thisObj, this[i], i, this);
            }
        }
    }
}); 
}();