jQuery 源码基本框架
抽丝剥茧, 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 源码基本框架的更多相关文章
- jQuery源码整体结构(源码2.0.3)
拨开jQuery的面纱,最近了解了下jQuery源码整体框架.主要包括: (1) jQuery 核心模块 (2) sizzle 选择器引擎 (3) Deferred 异步队列 (4) Supp ...
- jQuery源码分析之整体框架
之前只是知道jQuery怎么使用,但是我觉得有必要认真的阅读一下这个库,在分析jQuery源码之前,很有必要对整个jQuery有个整体的框架概念,才能方便后面对jQuery源码的分析和学习,以下是我总 ...
- 三.jQuery源码解析之jQuery的框架图
这张图片是对jQuery源码截图,一点一点拼出来的. 现在根据这张图片来对jQuery框架做一些说明. 一.16~9404行可以发现,最外层是一个自调用函数.当jQuery初始化时,这个自调用函数包含 ...
- 读jQuery源码之整体框架分析
读一个开源框架,大家最想学到的就是设计的思想和实现的技巧.最近读jQuery源码,记下我对大师作品的理解和心得,跟大家分享,权当抛砖引玉. 先附上jQuery的代码结构. (function(){ / ...
- jQuery源码学习感想
还记得去年(2015)九月份的时候,作为一个大四的学生去参加美团霸面,结果被美团技术总监教育了一番,那次问了我很多jQuery源码的知识点,以前虽然喜欢研究框架,但水平还不足够来研究jQuery源码, ...
- jQuery源码:从原理到实战
jQuery源码:从原理到实战 jQuery选择器对象 $(".my-class"); document.querySelectorAll*".my-class" ...
- JQuery源码解析(一)
写在前面:本<JQuery源码解析>系列是基于一些前辈们的文章进行进一步的分析.细化.修改而写出来的,在这边感谢那些慷慨提供科普文档的技术大拿们. 要查阅JQ的源文件请下载开发版的JQ.j ...
- jQuery源码笔记(一):jQuery的整体结构
jQuery 是一个非常优秀的 JS 库,与 Prototype,YUI,Mootools 等众多的 Js 类库相比,它剑走偏锋,从 web 开发的实用角度出发,抛除了其它 Lib 中一些中看但不实用 ...
- jquery 源码解析
静态与实力方法共享设计 遍历方法 $(".a").each() //作为实例方法存在 $.each() //作为静态方法存在 Jquery源码 jQuery.prototype = ...
随机推荐
- JavaScript高级程序设计4.pdf
虽然执行环境的类型总共只有两种——全局和局部(函数),但还有其他方法延长作用域链,有些语句可以在作用域链的前端临时增加一个变量对象,执行后会被移除try-catch语句的catch块和with语句 w ...
- poj 1050 To the Max (简单dp)
题目链接:http://poj.org/problem?id=1050 #include<cstdio> #include<cstring> #include<iostr ...
- liststack——链表栈(procedure)
#include <stdio.h> #include <stdlib.h> #include <string.h> #include "list.h&q ...
- (转)Linux中的文件描述符
本文转自:http://blog.csdn.net/cywosp/article/details/38965239 作者:cywosp 1. 概述 在Linux系统中一切皆可以看成是文件,文件又可分为 ...
- m版页面判断安卓与ios系统
安卓系统和ios系统,在做app里面嵌入m版时,有时候会发现,ios上面的那个电池状态栏不占位置,但是安卓的状态栏占位,所以需要区分系统样式单独处理一下! var sUserAgent=navigat ...
- 深入理解C#:编程技巧总结(一)
原创文章,转载请注明出处! 以下总结参阅了:MSDN文档.<C#高级编程>.<C#本质论>.前辈们的博客等资料,如有不正确的地方,请帮忙及时指出!以免误导! 1.实现多态性的两 ...
- c#语言基础编程—string
引言 在c#中经常会有相关的string的操作,string类型为引用类型,集成于Object,所以会有四个方法.详情可见 值类型和引用类型的区别 里面详细介绍了,值类型和引用类型的区别和应用场合,所 ...
- 不要在精确计算中使用float和double类型
http://blog.csdn.net/androiddevelop/article/details/8478879 一 问题描述 float和double类型不能用于精确计算,其主要目的是为了科 ...
- 海思android4.4 SDK编译Latin输入法
原来的HiSTBAndroidV500R001C01SPC020\device\hisilicon\bigfish\packages\apps\HiLatinIME\Android.mk内容例如以下: ...
- 【Spring五】AOP之使用注解配置
AOP使用注解配置流程: 1.当spring容器启动时候. < context:component- scan base-package= "cn.itheima03.sprin ...