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. Yarn application has already exited with state FINISHED

    如果在运行spark-sql时遇到如下这样的错误,可能是因为yarn-site.xml中的配置项yarn.nodemanager.vmem-pmem-ratio值偏小,它的默认值为2.1,可以尝试改大 ...

  2. QGIS Server Quickstart

    http://live.osgeo.org/en/quickstart/qgis_mapserver_quickstart.html

  3. opencv学习_4(opencv基础数据结构 CvPoint & CvSize & CvRect & CvScalar & CvArr & CvMat)

    1:包含在cxcore/include/cxtypes.h头文件中. 2:CvPoint系列   -----(x,y) CvPoint:表示图像中的点 CvPoint2D32f:二维空间中的点 CvP ...

  4. hdu 2780 Su-Su-Sudoku(DFS数独)

    题目链接:hdu2780 #include<stdio.h> #include<string.h> #include<queue> #include<math ...

  5. Java何时该使用覆盖?

    在Java编程中,什么时候该使用覆盖函数操作呢,很多人都知道有覆盖操作,但是到底什么时候该使用覆盖操作,还是有一些模糊的感觉,以下就举例来用代码分析就明白了, 举例生活中的案例,模拟制造手机的公司: ...

  6. XML字符串反序列化为实体

    JSON反序列化实体 paydata = StringHelper.Base64ToString(paydata); resInfo = JsonConvert.DeserializeObject&l ...

  7. Js加密算法

    使用crypto-js在浏览器上对数据加密签名 重要知识点: CryptoJS.lib.WordArray  WordArray对象可以理解为byte[] CryptoJS.enc 提供编码转换,从字 ...

  8. NetCore入门篇:(五)Net Core项目使用静态文件

    一.简介 1.Net Core默认无法访问静态文件,需要在Startup通过代码添加定义. 2.本文介绍两种静态文件目录实现方式. 二.启用默认目录 1.添加图片文件 2.测试访问结果(不能访问) 3 ...

  9. ASP.NET Core 2 学习笔记(八)URL重写

    路由跟URL 重写的功能性略有不同.路由是将Request 找到对应的服务,而URL 重写是为了推卸责任转送Request.本篇将简单介绍下ASP.NET Core的URL重写(URL Rewrite ...

  10. C#扩展一个现有的类

    做个记录,写个示例 using System; class Rubbish { public void Say() { Console.Write("Hello"); } } st ...