jquery source learning -1- overall architecture

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>jquery1.0.1</title>
    </head>
    <body>
        <script src="./jquery.1.0.1.js"></script>
        <script>
            // console.log($())
            /*
                init
                    __proto__: Object
                        css: ()
                        init: ()
                        the __proto__: Object 
            * /             
            var RET = {name: ' max ' , List: {Age: ' 30 ' }}
             var RES = {List: {Sex: ' F ' }}
             var obj = $ .extend ({}, RET , RES) // to extend any object, shallow copy 
            var OBJ1 = $ .extend ( to true , {}, RET, RES) // to extend any object, a deep copy 
            // $ .extend ({// jquery to expansion 
            / /      Work: function () {} 
            // }) 
            //JQuery.work // (); 
            // $ .fn.extend ({// object extension to an instance 
            //      Sex: 'M' 
            // }) 
            // $ () Sex. 
        </ Script > 
    </ body > 
< / HTML >
( Function (the root) {
     var the jQuery = function () {
         return  new new jQuery.prototype.init () 
    } 
    the jQuery.fn = jQuery.prototype = { 
        the init: function () {}, 
        CSS: function () {} 
    } 
    // internal extend | external 
    // shallow copy, deep copy (first parameter to true) 
    jQuery.fn.extend = jQuery.extend = function () { // is achieved according to the content and the number of parameters 
        var target = arguments [0] || {}
         var length = The arguments.length;
         var. 1 = I ;
         var deep = to false ;
         var Option, name, Copy, the src, copyIsArray, clone;
         IF ( typeof target === 'boolean') { // determines whether copy depth identification, if it is a boolean 
            deep = target; // Deel copy identification 
            target = arguments [. 1];   // to be assigned to the copied object second parameter 
            I = 2;   // to traverse from the second parameter starts 
        }
         IF ( typeof target == '! Object ') { // The first parameter is not an object, the object is null give him assignment 
            target = {} 
        } 
        IF(I === length) { // determine the number of parameters, if the number of parameters is 1, it is jquey / jquery extension object instances of objects,            
            target = this ; // refer to this object just 
            i-- 
        } 
        / / shallow copy 
        for (; I <length; I ++) { // if the number of parameters is 1, beginning from the second parameter, if it is 0, beginning from the first one, a useless consumption 
            IF ((Option = ! arguments [I]) = null ) {
                 for (name in Option) { 
                    Copy = Option [name] 
                    the src = target [name];
                     IF(deep && (jQuery.isPlainObject(copy) || (copyIsArray = jQuery.isArray(copy)))){   //深拷贝
                        if(copyIsArray){
                            copyIsArray = false;
                            clone = src && jQuery.isArray(src)? src :[];
                        }else{                            
                            clone = src && jQuery.isPlainObject(src)? src :{};
                        }
                        target[name] = jQuery.extend(deep,clone,copy)
                    }else if(copy != undefined){ // shallow copy 
                        target [name] = Copy; 
                    } 
                } 
            } 
        } 
        return target 
    } 

    // jQuery.prototype.init.prototype = jQuery.prototype; // shared prototype object 
    jQuery.fn.init.prototype = the jQuery.fn; / / shared prototype objects ,, fn prototype is shorthand for it. . . 

    jQuery.extend ({ 
        isPlainObject: function (obj) {
             return toString.call (obj) === '[Object Object]' 
        }, 
        the isArray: function (obj) {
             return toString.call (obj) === '[Object aarray] '
        }
    })
    root.$ = root.jQuery = jQuery
})(this)

 

Guess you like

Origin www.cnblogs.com/slightFly/p/11441840.html