非常适合新手的jq/zepto源码分析04
$.extend = function(target){
var deep, args = slice.call(arguments, 1)
if (typeof target == 'boolean') {
deep = target
target = args.shift()
}
args.forEach(function(arg){ extend(target, arg, deep) })
return target
}
扩展函数 第一个参数为boolean true 则深扩展,
zepto.qsa = function(element, selector){
var found,
maybeID = selector[0] == '#',
maybeClass = !maybeID && selector[0] == '.',
nameOnly = maybeID || maybeClass ? selector.slice(1) : selector, // Ensure that a 1 char tag name still gets checked
isSimple = simpleSelectorRE.test(nameOnly)
return (element.getElementById && isSimple && maybeID) ? // Safari DocumentFragment doesn't have getElementById
( (found = element.getElementById(nameOnly)) ? [found] : [] ) :
(element.nodeType !== 1 && element.nodeType !== 9 && element.nodeType !== 11) ? [] :
slice.call(
isSimple && !maybeID && element.getElementsByClassName ? // DocumentFragment doesn't have getElementsByClassName/TagName
maybeClass ? element.getElementsByClassName(nameOnly) : // If it's simple, it could be a class
element.getElementsByTagName(selector) : // Or a tag
element.querySelectorAll(selector) // Or it's not simple, and we need to query all
)
}
getElementByClassName 通过class获取节点
getElementByTagName 通过标签回去
获取单个选择器
$.contains = document.documentElement.contains ?
function(parent, node) {
return parent !== node && parent.contains(node)
} :
function(parent, node) {
while (node && (node = node.parentNode))
if (node === parent) return true
return false
}
document.documentElement.contains 检测某个节点下是否包含传入的子节点
$.type = type //检测对象类型
$.isFunction = isFunction //是否为函数
$.isWindow = isWindow //是否为window对象
$.isArray = isArray //是否为数组
$.isEmptyObject //是否为空对象
$.isNumeric //是否为有效数字
$.inArray //array的indexof
$.camelCase //驼峰命名
$.trim //去空
$.map //遍历函数,返回一个返回值的集合数组
$.each //遍历元素执行函数
$.grep //array的filter函数
代码仅供参考,具体功能可以自己扩展。
http://www.cnblogs.com/jiebba/p/6529854.html
http://www.cnblogs.com/jiebba 我的博客,来看吧!
如果有错误,请留言修改下 哦!
非常适合新手的jq/zepto源码分析04的更多相关文章
- 非常适合新手的jq/zepto源码分析07---ajax的封装
复习下ajax吧! 1.创建XMLHttpRequest对象 xmlhttp=new XMLHttpRequest(); xmlhttp=new ActiveXObject("Microso ...
- 非常适合新手的jq/zepto源码分析08---ajax的封装
1.现在看看对JSONP的封装 $.ajaxJSONP = function(options, deferred){ if (!('type' in options)) return $.ajax(o ...
- 非常适合新手的jq/zepto源码分析06 -- 事件模型
复习下事件的有关内容: 1.现在用的绑定/删除: obj.addEventListener(type,fn,false) obj.removeEventListener(type) obj.attac ...
- 非常适合新手的jq/zepto源码分析05
zepto的原型 $.fn 属性: constructor //构造行数 forEach: emptyArray.forEach, //都是原生数组的函数reduce: emptyArray.re ...
- 非常适合新手的jq/zepto源码分析03
zepto.fragment = function(html, name, properties) { var dom, nodes, container // 如果是简单的标签<div> ...
- 非常适合新手的jq/zepto源码分析01
(function(global, factory) { // 查看这里是不是定义成模块,如果定义模块就返回 一个模块 if (typeof define === 'function' &&a ...
- 非常适合新手的jq/zepto源码分析02
function isPlainObject(obj) { return isObject(obj) && !isWindow(obj) && Object.getPr ...
- zepto源码分析系列
如果你也开发移动端web,如果你也用zepto,应该值得你看看.有问题请留言. Zepto源码分析-架构 Zepto源码分析-zepto(DOM)模块 Zepto源码分析-callbacks模块 Ze ...
- 一个普通的 Zepto 源码分析(二) - ajax 模块
一个普通的 Zepto 源码分析(二) - ajax 模块 普通的路人,普通地瞧.分析时使用的是目前最新 1.2.0 版本. Zepto 可以由许多模块组成,默认包含的模块有 zepto 核心模块,以 ...
随机推荐
- ACM_Hailstone HOTPO
Hailstone HOTPO Time Limit: 2000/1000ms (Java/Others) Problem Description: The hailstone sequence is ...
- RabbitMQ三:Rabbit的安装
本章文章,摘自 园友 章为忠 的文章,查找了很多资料,他总结的最细,最全面,我就直接拿过来了 他的原文 http://www.cnblogs.com/zhangweizhong/p/5689209.h ...
- 向listview控件中添加数据库数据
//连接字符串 string str = "Data Source=.;Initial Catalog=mu;User ID=sa;Password=111"; //创建数据库连接 ...
- .Net MVC 前台验证跟后台验证
前台验证: 首先你得有一个参数类,参数类代码如下 验证标记总结 [DisplayName("邮箱:")] [Required(ErrorMessage = " ...
- CSV文件转EXCEl(java)
package main; import java.io.BufferedReader;import java.io.DataInputStream;import java.io.File;impor ...
- Scala-基础-函数(1)
import junit.framework.TestCase //函数(1) class Demo5 extends TestCase { def testDemo(){ println(" ...
- Laravel5.1学习笔记21 EloquentORM 集合
Eloquent: Collections Introduction Available Methods Custom Collections Introduction All multi-resul ...
- Git在工作中对项目的操作流程
Git 的准备工作 第一步:Git初始化 第一次在电脑上使用时,应该初始化操作,以后再使用Git操作,无需初始化,直接进行Git其他操作 git config --global user.name & ...
- Matlab2014的下载和安装激活过程
Matlab2014的下载和安装过程 转载自csdn https://blog.csdn.net/hp910315/article/details/70197149 1 下载Matlab2014,下 ...
- JavaScript 单例,Hash,抛异常
1. 单例 ECMA 5 版 记得以前写过几种单例实现,找不到了... function Singleton() { if (this.constructor.instance) { return t ...