-
Notifications
You must be signed in to change notification settings - Fork 58
Open
Labels
Description
我认为是这样的
zepto.init = function(selector, context) {
var dom // dom 集合
if (!selector) return zepto.Z() // 分支1
else if (typeof selector == 'string') { // 分支2
selector = selector.trim()
if (selector[0] == '<' && fragmentRE.test(selector))
dom = zepto.fragment(selector, RegExp.$1, context), selector = null
else if (context !== undefined) return $(context).find(selector)
else dom = zepto.qsa(document, selector)
}
else if (isFunction(selector)) return $(document).ready(selector) // 分支3
else if (zepto.isZ(selector)) return selector // 分支4
else { // 分支5
if (isArray(selector)) dom = compact(selector)
else if (isObject(selector))
dom = [selector], selector = null
else if (fragmentRE.test(selector))
dom = zepto.fragment(selector.trim(), RegExp.$1, context), selector = null
else if (context !== undefined) return $(context).find(selector)
else dom = zepto.qsa(document, selector)
}
return zepto.Z(dom, selector)
}分支2 是 selector 是字符串的情况下处理 zepto.fragment()的, 像 $('<div>')
分支5 引用类型下,不是数组,不是对象,未知名引用自动转为 html 调用 zepto.fragment()的, 我也具不出拿例子, 或者是 $(zepto collection) ?
但添加了还是有作用的,逻辑上面的严谨.
Reactions are currently unavailable