jQuery 2.0.3 源码分析之core(一)整体架构

2020-05-23 06:18:12易采站长站整理

                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 {    被拷贝的属性值是个plainObject,比如{ nick: ‘casper’ }
                        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 ) {  // 浅拷贝,且属性值不为undefined
                    target[ name ] = copy;