非常適合新手的jq zepto原始碼分析01

2022-09-15 05:30:10 字數 2168 閱讀 2421

(function(global, factory) )

else

factory(global) //直接執行閉包外傳過來的函式 funcutin(window)

}

var undefined, key, $, classlist, emptyarray = , concat = emptyarray.concat, filter = emptyarray.filter, slice = emptyarray.slice,

document = window.document,

elementdisplay = {}, classcache = {},

cssnumber = ,

fragmentre = /^\s*<(\w+|!)[^>]*>/,

singletagre = /^<(\w+)\s*\/?>(?:<\/\1>|)$/,

tagexpanderre = /<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:]+)[^>]*)\/>/ig,

rootnodere = /^(?:body|html)$/i,

capitalre = /([a-z])/g,

// special attributes that should be get/set via method calls

methodattributes = ['val', 'css', 'html', 'text', 'data', 'width', 'height', 'offset'],

table = document.createelement('table'),

tablerow = document.createelement('tr'),

containers = ,

readyre = /complete|loaded|interactive/,

******selectorre = /^[\w-]*$/,

class2type = {},

tostring = class2type.tostring,

zepto = {},

camelize, uniq,

tempparent = document.createelement('div'),

propmap = ,

isarray = array.isarray ||

function(object)

zepto.matches = function(element, selector)

1.  fragmentre = /^\s*<(\w+|!)[^>]*>/;

這裡複習下正規表示式

\s   -->   [\f\n\r\t\v]    

\f  -->  [\x0c\cl]

\n  -->  [\x0a\cj]

\r  -->  [\x0d\cm]

\t  -->  [\x09\cl]

\v -->  [\x0b\ck]

*  ()

\w --> [a-za-z0-9_]

+ a|b

^ 整個連起來就是配置 沒有結束標籤的的 html標籤    

2.singletagre = /^<(\w+)\s*\/?>(?:<\/\1>|)$/

? ?:

\ 匹配html標籤

3.tagexpanderre = /<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:]+)[^>]*)\/>/ig,

?! 配置特殊屬性

zepto.matches = function(element, selector)

matchesselector  接收乙個selector的css選擇符引數,如果呼叫元素與該選擇符相匹配,返回true;否則返回false

zepto.qsa   接受乙個selector的選中css選擇器獲取匹配元素

element下是否可以匹配到selector 

function type(obj)

{}.tostring.call(obj)    

返回obj 的型別

**僅供參考,具體功能可以自己擴充套件。

我的部落格,來看吧!

非常適合新手的jq zepto原始碼分析01

function global,factory else factory global 直接執行閉包外傳過來的函式 funcutin window var undefined,key,classlist,emptyarray concat emptyarray.concat,filter empty...

非常適合新手的jq zepto原始碼分析02

function isplainobject obj object.getprototypeof obj 返回 obj 的原型 這是檢視是不是簡單的物件 function likearray obj length in obj 物件obj是否有length屬性 是否為類陣列 compact arra...

非常適合新手的jq zepto原始碼分析05

zepto的原型 fn 屬性 constructor 構造行數foreach emptyarray.foreach,都是原生陣列的函式 reduce emptyarray.reduce,push emptyarray.push,sort emptyarray.sort,splice emptyarr...