抽丝剥茧, 7000+ 行的 jQuery 源码基本可以概括为以下的伪代码

(function (window, undefined) {
//将 document 封装成 jQuery 对象并缓存
var rootjQuery, //dom ready 事件的委托队列
readyList, //快速地识别 html 标记 如 <div> 或者 #id
rquickExpr = /^(?:\s*(<[\w\W]+>)[^>]*|#([\w-]*))$/, jQuery = function (selector, context) {
return new jQuery.fn.init(selector, context, rootjQuery);
}; jQuery.fn = jQuery.prototype = {
constructor: jQuery,
init: function (selector, context, rootjQuery) { // $(""), $(null), $(undefined), $(false)
if (!selector) {
return this;
} var match = rquickExpr.exec(selector); // $('<div></div>')
jQuery.parseHTML(match[1])
return this; // $(#id)
return document.getElementById(selector); // $('.class'), $('.class', context), $('#class', context)
// 其中 context 是jQuery元素
return (context || rootjQuery).find(selector); // $('.class', domElm)
return this.constructor(context).find(selector); // selector is function
return rootjQuery.ready(selector); return jQuery.makeArray(selector, this);
},
ready: function (fn) {
// Add the callback
jQuery.ready.promise().done(fn); return this;
}
} jQuery.init.prototype = jQuery.fn; jQuery.extend = jQuery.fn.extend = function () {
}; rootjQuery = jQuery(document); // Sizzle 代码
(function (window, undefined) { function Sizzle(selector, context, results, seed) {
if (support.qsa) {
return querySelectorAll(selector)
} return select(selector.replace(rtrim, "$1"), context, results, seed);
} function select(selector, context, results, seed) {
var match = tokenize(selector);
} function tokenize(selector, parseOnly) { } jQuery.find = Sizzle;
})(window); // 对 jQuery 对象的扩展
jQuery.extend({}); // 对 jQuery.fn 对象的扩展
jQuery.fn.extend({}); window.$ = window.jQuery = jquery; })(window);

jQuery 源码基本框架的更多相关文章

  1. jQuery源码整体结构(源码2.0.3)

    拨开jQuery的面纱,最近了解了下jQuery源码整体框架.主要包括: (1)  jQuery 核心模块 (2)  sizzle 选择器引擎 (3)  Deferred 异步队列 (4)  Supp ...

  2. jQuery源码分析之整体框架

    之前只是知道jQuery怎么使用,但是我觉得有必要认真的阅读一下这个库,在分析jQuery源码之前,很有必要对整个jQuery有个整体的框架概念,才能方便后面对jQuery源码的分析和学习,以下是我总 ...

  3. 三.jQuery源码解析之jQuery的框架图

    这张图片是对jQuery源码截图,一点一点拼出来的. 现在根据这张图片来对jQuery框架做一些说明. 一.16~9404行可以发现,最外层是一个自调用函数.当jQuery初始化时,这个自调用函数包含 ...

  4. 读jQuery源码之整体框架分析

    读一个开源框架,大家最想学到的就是设计的思想和实现的技巧.最近读jQuery源码,记下我对大师作品的理解和心得,跟大家分享,权当抛砖引玉. 先附上jQuery的代码结构. (function(){ / ...

  5. jQuery源码学习感想

    还记得去年(2015)九月份的时候,作为一个大四的学生去参加美团霸面,结果被美团技术总监教育了一番,那次问了我很多jQuery源码的知识点,以前虽然喜欢研究框架,但水平还不足够来研究jQuery源码, ...

  6. jQuery源码:从原理到实战

    jQuery源码:从原理到实战 jQuery选择器对象 $(".my-class"); document.querySelectorAll*".my-class" ...

  7. JQuery源码解析(一)

    写在前面:本<JQuery源码解析>系列是基于一些前辈们的文章进行进一步的分析.细化.修改而写出来的,在这边感谢那些慷慨提供科普文档的技术大拿们. 要查阅JQ的源文件请下载开发版的JQ.j ...

  8. jQuery源码笔记(一):jQuery的整体结构

    jQuery 是一个非常优秀的 JS 库,与 Prototype,YUI,Mootools 等众多的 Js 类库相比,它剑走偏锋,从 web 开发的实用角度出发,抛除了其它 Lib 中一些中看但不实用 ...

  9. jquery 源码解析

    静态与实力方法共享设计 遍历方法 $(".a").each() //作为实例方法存在 $.each() //作为静态方法存在 Jquery源码 jQuery.prototype = ...

随机推荐

  1. 苹果Think Different广告

    电视广告版: Here’s to the crazy ones. The misfits. The rebels. The troublemakers. The round pegs in the s ...

  2. CPP数组

    数组为函数参数,求出一组数中的最大者;

  3. Uncode-Schedule首页、文档和下载 - 分布式任务调度组件 - 开源中国社区

    Uncode-Schedule首页.文档和下载 - 分布式任务调度组件 - 开源中国社区 分布式任务调度组件 Uncode-Schedule

  4. SharePoint 2013的100个新功能之网站管理(二)

    一:SharePoint 2013的网站策略 网站策略指的是自动关闭或删除网站的条件.有四个选项:不自动关闭或删除网站.自动删除网站.自动关闭并删除网站和运行一个工作流来关闭.删除网站. 二:新的主题 ...

  5. win7限制登录时间的设置方法

    win7使用Net User命令行语句限制登录时间的方法: 1.单击“开始”,然后单击“运行”. 2.在“打开”框中,键入cmd,然后单击“确定”. 3..键入 net user username / ...

  6. Java处理文件小例子--获取全国所有城市的坐标

    需求:前端展示数据,全国城市的坐标

  7. eclipse编辑器,怎么创建PHP和JAVA的工程项目?

    eclipse编辑器,怎么创建PHP和JAVA的工程项目.强大的eclipse,编写php或者java由你选择!!! 我为什么这么说? 我是新手,写下这篇文章,可能对新手会有一点点的帮助而已,然后为了 ...

  8. android十六进制颜色代码转换为int类型数值

    android开发中将十六进制颜色代码转换为int类型数值方法:Color.parseColor("#00CCFF")返回int数值;

  9. 构建ASP.NET MVC4+EF5+EasyUI+Unity2.x注入的后台管理系统(29)-T4模版

    原文:构建ASP.NET MVC4+EF5+EasyUI+Unity2.x注入的后台管理系统(29)-T4模版 这讲适合所有的MVC程序 很荣幸,我们的系统有了体验的地址了.演示地址 之前我们发布了一 ...

  10. 23web app实现上下左右滑动

    转载请说明出处:http://blog.csdn.net/wowkk/article/category/1619287 (创意系列) /*最近项目须要苹果电脑,假设您支持学生创业并愿意赞助我们一台,请 ...