1 JQuery内核

2018-05-30  本文已影响0人  一枝妖孽

1 jQuery的内核

(function( window, undefined ) {
       //这就是jQuery的原型
       var jQuery = function( selector, context ) {
           return new jQuery.fn.init( selector, context );
       }
       //利用jQuery选择器产生的对象就是jQuery产生的对象,
      //所以利用选择器产生的对象才拥有了jQuery中prototype中的内容
       jQuery.fn = jQuery.prototype = {
            ready:function(){},
            each:function(){},
            size:function(){}
       }
       //window.jQuery.prototype=window.jQuery.fn=window.$.fn=jQuery.prototype=$.prototype=$.fn
       window.jQuery = window.$ = jQuery;
       //把加在jQuery对象上的方法或者加jQuery.prototype上的方法称为jQuery的插件开发
       jQuery.a = function(){

       }
       jQuery.prototype.b = function(){}
       //总结:如果该方法与页面上的元素没有关系,该方法就为jQuery中全局的插件方法
       // 如果该方法与页面上的元素有关系,则方法就必须加在jQuery的prototype上
  })(window);
上一篇 下一篇

猜你喜欢

热点阅读