Ashley’s Blog

A blogging framework for Ashley.

JQuery Structure

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
;(function(global, factory) {
    factory(global);
}(typeof window !== "undefined" ? window : this, function(window, noGlobal) {
    var jQuery = function( selector, context ) {
      return new jQuery.fn.init( selector, context ); //确保构造函数的执行
  };
  jQuery.fn = jQuery.prototype = {...};
  init = jQuery.fn.init = function( selector, context ) {};
  init.prototype = jQuery.fn//把挂在fn上的方法都传给init prototype,这样Jquery对象就能拥有并使用了
  // 核心方法
  // 回调系统
  // 异步队列
  // 数据缓存
  // 队列操作
  // 选择器引
  // 属性操作
  // 节点遍历
  // 文档处理
  // 样式操作
  // 属性操作
  // 事件体系
  // AJAX交互
  // 动画引擎
  return jQuery;
}));

小技巧 ctrl+m 快速跳转到匹配的括号

----------------------

noconflict

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
var
  // Map over jQuery in case of overwrite
  _jQuery = window.jQuery, //把原jQuery对象保存到_jQuery

  // Map over the $ in case of overwrite
  _$ = window.$; //把原$对象保存到_$

jQuery.noConflict = function( deep ) {
  if ( window.$ === jQuery ) {
      window.$ = _$; //如果咱们代码中的JQuery已经鸠占鹊巢占有了window.$,就把他还原回去
  }

  if ( deep && window.jQuery === jQuery ) {
      window.jQuery = _jQuery;//如果他要求的更多(指deep),咱们把window.jQuery也还原回去
  }

  return jQuery;
};

珍藏了2个月的刘明湘漂洋过海来看你