非常适合新手的jq/zepto源码分析05
zepto的原型 $.fn 属性:
constructor //构造行数
forEach: emptyArray.forEach, //都是原生数组的函数reduce: emptyArray.reduce,push: emptyArray.push,sort: emptyArray.sort,splice: emptyArray.splice,indexOf: emptyArray.indexOf,
concat //合并数组,这里还包含了合并节点集合
add //添加节点集合
is //匹配是否包含该选择器
find: function(selector){var result, $this = thisif (!selector) result = $()else if (typeof selector == 'object')result = $(selector).filter(function(){var node = thisreturn emptyArray.some.call($this, function(parent){return $.contains(parent, node)})})else if (this.length == 1) result = $(zepto.qsa(this[0], selector))else result = this.map(function(){ return zepto.qsa(this, selector) })return result},
emptyArray.some() http://www.cnblogs.com/jiebba/p/6514067.html 可以看看js几种遍历不同
pluck 根据属性来返回节点集合
// 设置宽高;['width', 'height'].forEach(function(dimension){var dimensionProperty =dimension.replace(/./, function(m){ return m[0].toUpperCase() })$.fn[dimension] = function(value){var offset, el = this[0]if (value === undefined) return isWindow(el) ? el['inner' + dimensionProperty] :isDocument(el) ? el.documentElement['scroll' + dimensionProperty] :(offset = this.offset()) && offset[dimension]else return this.each(function(idx){el = $(this)el.css(dimension, funcArg(this, value, idx, el[dimension]()))})}})
//添加函数`after`, `prepend`, `before`, `append`,
adjacencyOperators.forEach(function(operator, operatorIndex) {var inside = operatorIndex % 2 //=> prepend, append$.fn[operator] = function(){// arguments can be nodes, arrays of nodes, Zepto objects and HTML stringsvar argType, nodes = $.map(arguments, function(arg) {var arr = []
zepto.Z.prototype = Z.prototype = $.fn
绑定到原型上面
window.Zepto = Zeptowindow.$ === undefined && (window.$ = Zepto)//绑定在全局
代码仅供参考,具体功能可以自己扩展。
个人博客 :很多好用的 npm 包 , 可以看看 https://gilea.cn/
http://www.cnblogs.com/jiebba/p/6529854.html
http://www.cnblogs.com/jiebba 我的博客,来看吧!
如果有错误,请留言修改下 哦!
非常适合新手的jq/zepto源码分析05相关推荐
- Mybatis3源码分析(05)-加载Configuration-加载MappedStatement
2019独角兽企业重金招聘Python工程师标准>>> Mybatis3源码分析(05)-加载Configuration-加载MappedStatement 博客分类: java m ...
- Zepto源码分析-event模块
源码注释 // Zepto.js // (c) 2010-2015 Thomas Fuchs // Zepto.js may be freely distributed under the MIT l ...
- Zepto源码分析-zepto模块
源码 //Zepto.js//(c) 2010-2015 Thomas Fuchs//Zepto.js may be freely distributed under the MIT license. ...
- llvm libLLVMCore源码分析 05 - Instruction Class
源码路径 llvm\include\llvm\IR\Instruction.h llvm\include\llvm\IR\Instruction.def llvm\include\llvm\IR\In ...
- Zepto源码分析-架构
构造函数 Zepto.js 是专门为智能手机浏览器推出的javascript库, 拥有与和jQuery相似的语法. 它的优点是精简,压缩后5-10K. 不支持IE MIT开源协议 结构 http: ...
- Libev源码分析05:Libev中的绝对时间定时器
Libev中的超时监视器ev_periodic,是绝对时间定时器,不同于ev_timer,它是基于日历时间的.比如如果指定一个ev_periodic在10秒之后触发(ev_now() + 10),然后 ...
- 读Zepto源码之操作DOM
2019独角兽企业重金招聘Python工程师标准>>> 这篇依然是跟 dom 相关的方法,侧重点是操作 dom 的方法. 读Zepto源码系列文章已经放到了github上,欢迎sta ...
- 读Zepto源码之代码结构
虽然最近工作中没有怎么用 zepto ,但是据说 zepto 的源码比较简单,而且网上的资料也比较多,所以我就挑了 zepto 下手,希望能为以后阅读其他框架的源码打下基础吧. 源码版本 本文阅读的源 ...
- 读Zepto源码之Deferred模块
Deferred 模块也不是必备的模块,但是 ajax 模块中,要用到 promise 风格,必需引入 Deferred 模块.Deferred 也用到了上一篇文章<读Zepto源码之Callb ...
最新文章
- RavenDB FS 安装使用 介绍
- srm linux字符界面,如何使用srm安全的删除Linux中的文件
- 5.1 Tensorflow:图与模型的加载与存储
- 华为交换机netstream配置
- requestmapping配置页面后_@RequestMapping接口及页面乱码问题
- numpy 数组抽取_Python 关于NumPy的用法介绍
- c3p0 高并发mysql 连接sleep情况
- C#引用office库
- Canvas scale- 缩放
- 最近项目中遇到的一个算法挑战
- vSphere5.1升级5.5(二)——升级Esxi主机及vmware tools
- Activity 切换 动画
- 异常Throwable类
- 云南昭通暴雨强度公式_玉溪市中心城区暴雨强度公式
- python 爬虫之路教程
- js数组操作方法 concat
- 苹果支付在哪里设置_微信刷脸支付怎么开通,在哪里设置?
- 博客:固定位置增加二维码
- 如何在html里面搜索代码,怎样在网页里查找关键字
- 429. N 叉树的层序遍历 c++ 队列