您好,欢迎访问一九零五行业门户网

jQuery extend 的简单实例_jquery

复制代码 代码如下:
jquery.extend = jquery.fn.extend = function() {
    var options, name, src, copy, copyisarray, clone,
        target = arguments[0] || {},
        i = 1,
        length = arguments.length,
        deep = false;    // handle a deep copy situation
    if ( typeof target === boolean ) {
        deep = target;
        target = arguments[1] || {};
        // skip the boolean and the target
        i = 2;
    }
    // handle case when target is a string or something (possible in deep copy)
    if ( typeof target !== object && !jquery.isfunction(target) ) {
        target = {};
    }
    // extend jquery itself if only one argument is passed
    if ( length === i ) {
        target = this;
        --i;
    }
    for ( ; i         // only deal with non-null/undefined values
        if ( (options = arguments[ i ]) != null ) {
            // extend the base object
            for ( name in options ) {
                src = target[ name ];
                copy = options[ name ];
                // prevent never-ending loop
                if ( target === copy ) {
                    continue;
                }
                // recurse if we're merging plain objects or arrays
                if ( deep && copy && ( jquery.isplainobject(copy) || (copyisarray = jquery.isarray(copy)) ) ) {
                    if ( copyisarray ) {
                        copyisarray = false;
                        clone = src && jquery.isarray(src) ? src : [];
                    } else {
                        clone = src && jquery.isplainobject(src) ? src : {};
                    }
                    // never move original objects, clone them
                    target[ name ] = jquery.extend( deep, clone, copy );
                // don't bring in undefined values
                } else if ( copy !== undefined ) {
                    target[ name ] = copy;
                }
            }
        }
    }
    // return the modified object
    return target;
};
其它类似信息

推荐信息