preFilter: {
"ATTR": function( match ) {
//属性名解码
match[1] = match[1].replace( runescape, funescape ); // Move the given value to match[3] whether quoted or unquoted
//属性解码
match[3] = ( match[3] || match[4] || match[5] || "" ).replace( runescape, funescape ); //若判断符为~=,则在属性值两边加上空格
if ( match[2] === "~=" ) {
match[3] = " " + match[3] + " ";
} //返回前4个元素
return match.slice( 0, 4 );
}, "CHILD": function( match ) {
/* matches from matchExpr["CHILD"]
1 type (only|nth|...)
2 what (child|of-type)
3 argument (even|odd|\d*|\d*n([+-]\d+)?|...)
4 xn-component of xn+y argument ([+-]?\d*n|)
5 sign of xn-component
6 x of xn-component
7 sign of y-component
8 y of y-component
*/
//match[1]:(only|first|last|nth|nth-last)
//match[2]: (child|last-child|of-type|last-of-type)
//match[3]: (even|odd)
//match[4]、match[5]: an+b中的a,b //match[1]变成小写
match[1] = match[1].toLowerCase(); //如果match[1]是"nth"
if ( match[1].slice( 0, 3 ) === "nth" ) {
// nth-* requires argument
//若选择器括号内没有有效参数,则抛出异常
if ( !match[3] ) {
Sizzle.error( match[0] );
} // numeric x and y parameters for Expr.filter.CHILD
// remember that false/true cast respectively to 0/1
/*
* 下面先以nth-child()为例介绍一下语法,以便更好的理解下面代码的作用
* nth-child允许的几种使用方式如下:
* :nth-child(even)
* :nth-child(odd)
* :nth-child(3n)
* :nth-child(+2n+1)
* :nth-child(2n-1)
* 下面代码中赋值号左侧的match[4]、match[5]用于分别记录括号内n前及n后的数值,包括正负号
* 对于:nth-child(even)和:nth-child(odd)来说,match[4]为空,
* 所以返回 2 * (match[3] === "even" || match[3] === "odd")的计算结果
* 因为在js中true=1,false=0,所以(match[3] === "even" || match[3] === "odd")等于1
* 因此,2 * (match[3] === "even" || match[3] === "odd")的计算结果为2
*
* 等号右侧的“+”的作用是强制类型转换,将之后的字符串转换成数值类型
*/
match[4] = +( match[4] ? match[5] + (match[6] || 1) : 2 * ( match[3] === "even" || match[3] === "odd" ) );
match[5] = +( ( match[7] + match[8] ) || match[3] === "odd" ); // other types prohibit arguments
//若非nth起头的其它CHILD类型选择器带有括号说明,则抛出异常
} else if ( match[3] ) {
Sizzle.error( match[0] );
} return match;
}, "PSEUDO": function( match ) {
var excess,
unquoted = !match[6] && match[2]; if ( matchExpr["CHILD"].test( match[0] ) ) {
return null;
} // Accept quoted arguments as-is
if ( match[3] ) {
match[2] = match[4] || match[5] || ""; // Strip excess characters from unquoted arguments
} else if ( unquoted && rpseudo.test( unquoted ) &&
// Get excess from tokenize (recursively)
(excess = tokenize( unquoted, true )) &&
// advance to the next closing parenthesis
(excess = unquoted.indexOf( ")", unquoted.length - excess ) - unquoted.length) ) { // excess is a negative index
match[0] = match[0].slice( 0, excess );
match[2] = unquoted.slice( 0, excess );
} // Return only captures needed by the pseudo filter method (type and argument)
return match.slice( 0, 3 );
}
},
 

【jQuery源码】preFilter的更多相关文章

  1. jQuery源码分析系列

    声明:本文为原创文章,如需转载,请注明来源并保留原文链接Aaron,谢谢! 版本截止到2013.8.24 jQuery官方发布最新的的2.0.3为准 附上每一章的源码注释分析 :https://git ...

  2. jQuery源码学习感想

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

  3. Jquery源码学习(第一天)

    jQuery是面向对象的设计通过window.$ = window.jQuery = $; 向外提供接口,将$挂在window下,外部就可以使用$和jQuery $("#div1" ...

  4. jQuery源码 Ajax模块分析

    写在前面: 先讲讲ajax中的相关函数,然后结合函数功能来具体分析源代码. 相关函数: >>ajax全局事件处理程序 .ajaxStart(handler) 注册一个ajaxStart事件 ...

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

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

  6. 【菜鸟学习jquery源码】数据缓存与data()

    前言 最近比较烦,深圳的工作还没着落,论文不想弄,烦.....今天看了下jquery的数据缓存的代码,参考着Aaron的源码分析,自己有点理解了,和大家分享下.以后也打算把自己的jquery的学习心得 ...

  7. 从jquery源码中看类型判断和数组的一些操作

    在深入看jquery源码中,大家会发现源码写的相当巧妙.那我今天也通过几个源码中用到的技巧来抛砖引玉,希望大家能共同研究源码之精华,不要囫囵吞枣. 1.将类数组转化成数组 我想大家首先想到的方法是fo ...

  8. 读艾伦的jQuery的无new构建,疑惑分析——jquery源码学习一

    背景: 有心学习jquery源码,苦于自己水平有限,若自己研究,耗时耗力,且读懂之日无期. 所以,网上寻找高手的源码分析.再经过自己思考,整理,验证.以求有所收获. 此篇为读高手艾伦<jQuer ...

  9. JQuery源码解析(一)

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

  10. 读jQuery源码 - Deferred

    Deferred首次出现在jQuery 1.5中,在jQuery 1.8之后被改写,它的出现抹平了javascript中的大量回调产生的金字塔,提供了异步编程的能力,它主要服役于jQuery.ajax ...

随机推荐

  1. Docker搭建 MySQL 主从复制

    为什么选 Docker 搭建主从复制需要两个以上的MySQL, 使用 Docker 非常方便.如果以前没用过,找个简单的文档看看,熟悉一下命令. 搭建过程 1.下载镜像 docker pull mys ...

  2. 二:nodejs+express+redis+bootstrap table+jquery UI

    介绍:做一个量化投资的实时系统. 综合: 添加记录,顺序改变的话,refresh之后,能正常刷新吗?可以正常刷新,只是顺序又变回去. express中用fs readfile 时,需要用path.jo ...

  3. SpringBoot tomcat

    该文的前提是已经可以在控制台运行成功,有些时候想放在tomcat里运行 大致分为如下几步 1.配置文件更改 <dependency> <groupId>org.springfr ...

  4. Sending Email In .NET Core 2.0

    Consider the following written in .NET Core 2.0. SmtpClient client = ) { UseDefaultCredentials = tru ...

  5. LeetCode145:Binary Tree Postorder Traversal

    题目: Given a binary tree, return the postorder traversal of its nodes' values. For example: Given bin ...

  6. ASP.NET MVC中设置跨域

    ASP.NET MVC中设置跨域 1.什么是跨域请求 js禁止向不是当前域名的网站发起一次ajax请求,即使成功respone了数据,但是你的js仍然会报错.这是JS的同源策略限制,JS控制的并不是我 ...

  7. ipad协议7.0,与大佬们分享几套新老版本的协议源码及算法,交流心得。

  8. MVC中使用Hangfire执行定时任务

    需求描述 项目中有一个通知公告的功能,在后台管理员添加公告后需要推送消息给所有注册用户,让其查看消息.消息推送移动端采用极光推送,但是消息在何时发送是个问题,比如说有一个重要的会议通知,可能希望在会议 ...

  9. js事件处理

    1.js中常用的事件处理程序(event Handler) onabort 用户终止了页面的加载 onblur 用户离开了对象 onchange 用户修改了对象 onclick 用户点击了对象 one ...

  10. Python廖雪峰学习笔记——单元测试

    定义:对一个模块.一个类.一个函数进行进行正确性检验的测试性工作.当我们对函数或者模块等进行修改时,单元测试就显得尤为重要. 单元测试 = 测试用例(用来测试的数据)+测试模块