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

2022-09-15 05:27:11 字數 1371 閱讀 4854

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))

})else if (this.length == 1) result = $(zepto.qsa(this[0], selector))

else result = this.map(function())

return result

},

emptyarray.some()        可以看看js幾種遍歷不同

pluck              根據屬性來返回節點集合
// 設定寬高

;['width', 'height'].foreach(function(dimension))

$.fn[dimension] = function(value))

}})

adjacencyoperators.foreach(function(operator, operatorindex) {

$.fn[operator] = function(){

// arguments can be nodes, arrays of nodes, zepto objects and html strings

var argtype, nodes = $.map(arguments, function(arg) {

var arr =

zepto.z.prototype = z.prototype = $.fn

繫結到原型上面

window.zepto = zepto

window.$ === undefined && (window.$ = zepto)

//繫結在全域性

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

我的部落格,來看吧!

非常適合新手的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原始碼分析04

extend function target args.foreach function arg return target 擴充套件函式 第乙個引數為boolean true 則深擴充套件,zepto.qsa function element,selector getelementbyclassn...