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); 
  • 相关阅读:
    作为一个程序猿,是不是经常会用到.chm文档,但是我们可能会遇到这样那样的问题,比如.chm文档打不开
    总结
    图片轮播的几种方式
    学习中于遇到的问题总结
    node 总结
    webpack 总结
    babel 的总结和理解
    关于css 的AST 语法树的理解
    js中的正则表达式
    八皇后
  • 原文地址:https://www.cnblogs.com/fe-huahai/p/5724066.html
Copyright © 2011-2022 走看看