惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

The Hacker News
The Hacker News
博客园_首页
人人都是产品经理
人人都是产品经理
博客园 - 聂微东
J
Java Code Geeks
Stack Overflow Blog
Stack Overflow Blog
Blog — PlanetScale
Blog — PlanetScale
博客园 - 三生石上(FineUI控件)
A
About on SuperTechFans
V
Visual Studio Blog
小众软件
小众软件
MyScale Blog
MyScale Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
F
Full Disclosure
酷 壳 – CoolShell
酷 壳 – CoolShell
T
The Exploit Database - CXSecurity.com
C
CERT Recently Published Vulnerability Notes
T
Threat Research - Cisco Blogs
AWS News Blog
AWS News Blog
T
Tor Project blog
Jina AI
Jina AI
GbyAI
GbyAI
C
Comments on: Blog
IT之家
IT之家
Apple Machine Learning Research
Apple Machine Learning Research
A
Arctic Wolf
有赞技术团队
有赞技术团队
SecWiki News
SecWiki News
L
Lohrmann on Cybersecurity
Security Latest
Security Latest
Webroot Blog
Webroot Blog
C
Cisco Blogs
雷峰网
雷峰网
云风的 BLOG
云风的 BLOG
博客园 - 叶小钗
K
Kaspersky official blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
宝玉的分享
宝玉的分享
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
O
OpenAI News
H
Hacker News: Front Page
D
Darknet – Hacking Tools, Hacker News & Cyber Security
D
Docker
P
Palo Alto Networks Blog
The Register - Security
The Register - Security
B
Blog RSS Feed
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
WordPress大学
WordPress大学
阮一峰的网络日志
阮一峰的网络日志

博客园 - sonkoto

HTML5添加的一些常用新标签 css判断ie浏览器 [jQuery] table表格 [jQuery] menu_Sliding(menu 滑动) [jQuery]animated-hover [jQuery]animate(滑块滑动) [jQuery]图片更换 [jQuery] simple-disappear (消失的例子)——【转】 [转]jQuery formValidator【表达校验插件】 table Editor[table排序] [jQuery] jQuery Plugins by Dylan Verheul [JQuery Cycle Plugin] 图片轮换 [jQuery] 漂亮的menu+样式表切换 JQuery Cycle Plugin (jQuery循环插件_图片轮换) [转]JQuery效果展示--不看后悔N辈子 [转]DOV+CSS表单:超炫的单选框与复选框效果! [转]【★】javascript 常用代码 超经典! 【转】jQuery下拉框,单选框,多选框整理 Flash:百叶窗 效果
[转]jQuery源码解读---执行过程分析
sonkoto · 2008-07-17 · via 博客园 - sonkoto

JavaScript是一门基于对象的语言,而它的对象技术的实现又和其他语言有着很大的差异,在JavaScript中,一个类的定义一般采用下面这种模式(我所看到的):

// 定义一个构造函数;
testClass(param1, param2) {
  
this.attr1 = param1;
  
this.attr2 = param2;
   ...
}
// 在prototype对象上扩展,加上相应的方法;
testClass.prototype = {
   Method1:
function() {...},
   Method2:
function() {...},
   ...
}
// 定义一个实例;
var test = new testClass();

  在jQuery.js中,同样也是这种模式,只不过它要复杂很多,而且它还定义了一个jQuery.extend()的静态方法来扩展类的功能,jQuery.js代码执行过程完整分析如下:

// 防止多次载入而进行jQuery对象的判断;
if ( typeof window.jQuery == "undefined" ) {
   window.undefined
= window.undefined;// jQuery的构造函数;
  var jQuery = function( a, c ) { ... };// jQuery的命名空间$;
  if ( typeof $ != "undefined" ) jQuery._$ = $;
  
var $ = jQuery;// 给jQuery的prototype增加一些基础方法和属性;
  // 其中有些方法是调用下面的扩展方法实现的;
  // 注意下面的jQuery.fn = jQuery.prototype;
   jQuery.fn = jQuery.prototype = {
     each:
function( fn, args ) { ... },
     find:
function( t ) { ... },
     ...
   };
// jQuery实现继承的方法;
   jQuery.extend = jQuery.fn.extend = function( obj, prop ) {...};// 实现一些基础的函数,有大部分是上面调用;
   jQuery.extend({
     init:
function() { ... },
     each:
function( obj, fn, args ) { ... },
     find:
function( t, context ) { ... },
     ...
   });
// 浏览器版本的检测;
  new function() {
     jQuery.browser
= { safari:..., opera:..., msie:..., mozilla:... };
     ...
   };
// jQuery.macros扩展,主要用于jQuery.init(),进行jQuery的初始化;
   jQuery.macros = {
     filter: [ ... ],
     attr: { ... },
     each: { ... },
     ...
   };
// jQuery初始化;
   jQuery.init();// 实现jQuery的重要方法ready();
   jQuery.fn.extend({
     ready:
function( f ) { ... }
     ...
   };
// 上面ready()方法的具体实现;
   jQuery.extend({
     ready:
function() { ... },
     ...
   };
// 对浏览器某些事件进行绑定和解绑定;
  new function() {
     ...
     jQuery.event.add( window,
"load", jQuery.ready );
   };
// 当IE浏览器关闭时,清除上面绑定的事件,防止内存泄漏;
  if ( jQuery.browser.msie ) jQuery(window).unload( ... );// 实现一些浏览器效果;
   jQuery.fn.extend({
     show:
function( speed, callback ) { ... },
     hide:
function( speed, callback ) { ... },
     ...
   };
// 上面的一些函数具体实现;
   jQuery.extend( {...} );// 以下都是Ajax的实现,这里声明原型,具体实现调用下面的函数;
   jQuery.fn.extend({
     loadIfModified:
function(url, params, callback ) { ... },
     ...
   };
// 针对IE浏览器创建不同的XMLHttpRequest对象;
  if (jQuery.browser.msie && typeof XMLHttpRequest == "undefined") { ... };// Ajax函数的绑定;
  new function() {
    
var e = "ajaxStart,ajaxStop,ajaxComplete,ajaxError,ajaxSuccess".split(",");
     ...
   };
// Ajax函数的具体实现;
   jQuery.extend({
     get:
function( url, data, callback, type, ifModified ) { ... },
     post:
function( url, data, callback, type ) { ... },
     ajax:
function( type, url, data, ret, ifModified ) { ... },
     ...
   }
}

转自:http://hi.baidu.com/zhuguoneng/blog/item/3d07e9d667e9482b06088b4c.html