zoukankan      html  css  js  c++  java
  • 构建jQuery对象的源代码分析转了

    (function (window, undefined) {
        
        // 构造jQuery对象
        var jQuery = (function () {
            
            //以下定义了内部变量
            // Define a local copy of jQuery
            
            var jQuery = function (selector, context) {
                // The jQuery object is actually just the init constructor 'enhanced'
                return new jQuery.fn.init(selector, context, rootjQuery);
            };
            
            //把jQuery的原型 prototype赋给jQuery.fn
            jQuery.fn = jQuery.prototype = {
                constructor : jQuery,
                /**
                 * selector有以下7种分支情况:
                DOM元素
                body(优化)
                字符串:HTML标签、HTML字符串、#id、选择器表达式
                函数(作为ready回调函数)
                最后返回伪数组
                 */
                init : function (selector, context, rootjQuery) {
                    //后期会详细分析此处的实现
                }
                
            };
            
            // Give the init function the jQuery prototype for later instantiation
            //把jQuery.fn赋值到jQuery.fn.init.prototype,这样init指向的原型prototype也具有了jQuery.fn的功能
            jQuery.fn.init.prototype = jQuery.fn;
            
            //jQuery的继承实现
            jQuery.extend = jQuery.fn.extend = function () {};
            
            // 在jQuery上扩展静态方法
            jQuery.extend({
                // ready bindReady
                // isPlainObject isEmptyObject
                // parseJSON parseXML
                // globalEval
                // each makeArray inArray merge grep map
                // proxy
                // access
                // uaMatch
                // sub
                // browser
            });
            
            // 到这里,jQuery对象构造完成,后边的代码都是对jQuery或jQuery对象的扩展
            return jQuery;
            
        })();
        
        // Expose jQuery to the global object
        //设置jQuery 和  $为window全局变量
        window.jQuery = window.$ = jQuery;
        
    })(window);
  • 相关阅读:
    BZOJ 1036 [ZJOI2008]树的统计Count(动态树)
    HDU 4010 Query on The Trees(动态树)
    Bootstrap框架
    【价格谈判】——在生意场合胜出的50个谈判绝招
    导出
    邓_ Php·魔术方法
    邓_tp_笔记
    UI 网页三原色
    邓_ 表单验证
    邓_ ThinkPhp框架
  • 原文地址:https://www.cnblogs.com/playerlife/p/2748571.html
Copyright © 2011-2022 走看看