zoukankan      html  css  js  c++  java
  • jquery 总体架构

     版本:1.7.1

     总体架构:

     1.执行jQuery(selector, context)方法,在方法内部实例化函数jQuery.fn.init,得到一个jquery对象。

     2.函数jQuery.fn.init属于jQuery原型上的方法。

     3.函数jQuery.fn.init的原型指向函数jQuery的原型。

     4.因此,生成的jquery对象继承了函数jQuery原型上的属性和方法。

     5.函数jQuery有自己的静态方法,直接使用 jQuery.方法名 来调用。

     6.此外,可通过jQuery.extend方法扩展jQuery的静态方法,通过使用jQuery.fn.extend方法扩展jquery对象的方法。

    如图1所示,函数jQuery拥有原型jQuery.prototype,原型jQuery.prototype拥有方法jQuery.prototype.init,函数jQuery.prototype.init拥有原型jQuery.prototype.init.prototype,原型jQuery.prototype.init.prototype指向原型jQuery.prototype。实例化函数jQuery.prototype.init得到一个jquery对象,jquery对象继承了函数jQuery.prototype.init的原型jQuery.prototype.init.prototype的属性和方法,即原型jQuery.prototype的属性和方法。

    图1 jquery总体架构

    代码如下:

    (function(window,undefined){
        var jQuery = (function(){
            var jQuery = function( selector, context ){
                return new jQuery.fn.init( selector, context, rootjQuery );
            };
    
            jQuery.fn = jQuery.prototype = {
                constructor: jQuery,
                init: function( selector, context, rootjQuery ){
                }
            };
            
            jQuery.fn.init.prototype = jQuery.fn;
    
            return jQuery;
        })();
    })(window); 
  • 相关阅读:
    递归获取指定盘符下的所有文件及文件夹
    单例模式和多线程有没有关系?
    eclipse启动tomcat时设置端口
    dozer转化对象
    枚举
    dubbo
    json
    配网失败问题
    esp_err_t esp_event_loop_init(system_event_cb_t cb, void *ctx);
    base64编码
  • 原文地址:https://www.cnblogs.com/fe-huahai/p/5724066.html
Copyright © 2011-2022 走看看