jQuery 1.0.4 - New Wave Javascript(js源文件)

2019-06-03 09:49:42刘景俊


        // Go through the array, only saving the items
        // that pass the validator function
        for ( var i = 0; i < elems.length; i++ )
            if ( !inv && fn(elems[i],i) || inv && !fn(elems[i],i) )
                result.push( elems[i] );

        return result;
    },

    map: function(elems, fn) {
        // If a string is passed in for the function, make a function
        // for it (a handy shortcut)
        if ( typeof fn == "string" )
            fn = new Function("a","return " + fn);

        var result = [];

        // Go through the array, translating each of the items to their
        // new value (or values).
        for ( var i = 0; i < elems.length; i++ ) {
            var val = fn(elems[i],i);

            if ( val !== null && val != undefined ) {
                if ( val.constructor != Array ) val = [val];
                result = jQuery.merge( result, val );
            }
        }

        return result;
    },

    /*
     * A number of helper functions used for managing events.
     * Many of the ideas behind this code orignated from Dean Edwards' addEvent library.