日本搞逼视频_黄色一级片免费在线观看_色99久久_性明星video另类hd_欧美77_综合在线视频

國內最全IT社區平臺 聯系我們 | 收藏本站
阿里云優惠2
您當前位置:首頁 > web前端 > jquery > jQuery1.3.2源碼學習7:setArray,each 函數

jQuery1.3.2源碼學習7:setArray,each 函數

來源:程序員人生   發布時間:2014-01-10 04:56:55 閱讀次數:3452次
119 // Take an array of elements and push it onto the stack
120 // (returning the new matched element set)
121 pushStack: function( elems, name, selector ) {
122 // Build a new jQuery matched element set
123 var ret = jQuery( elems );
// Add the old object onto the stack (as a reference)
126 ret.prevObject = this;

128 ret.context = this.context;

130 if ( name === "find" )
ret.selector = this.selector + (this.selector ? " " : "") + selector;
else if ( name )
ret.selector = this.selector + "." + name + "(" + selector + ")";

// Return the newly-formed element set
return ret;
137 },

121 行開始的 pushStack 方法用來將通過數組傳遞的一個集合,格式化成為一個標準的 jQuery 對象,這樣就可以使用 jQuery 提供的方法進行操作了。第 123 將數組轉化為一個 jQuery 對象。參見 91 行。
126 行通過 prevObject 屬性指向原來的數組對象,128行保存當前的環境引用。
130 行檢查是否要在數組上進行進一步的查詢,如果提供了查詢, 那么更新當前的選擇器 selector。
136 行,返回構造完成的 jQuery 對象。

// Force the current matched set of elements to become
// the specified array of elements (destroying the stack in the process)
// You should use pushStack() in order to do this, but maintain the stack
142 setArray: function( elems ) {
// Resetting the length to 0, then using the native Array push
// is a super-fast way to populate an object with array-like properties
this.length = 0;
Array.prototype.push.apply( this, elems );

return this;
},
142 行的 setArray 方法用來將通過參數傳遞進來的數組,替換掉當前的 jQuery 對象中的查詢結果。

// Execute a callback for every element in the matched set.
// (You can seed the arguments with an array of args, but this is
// only used internally.)
154 each: function( callback, args ) {
return jQuery.each( this, callback, args );
},
each 方法用來遍歷查詢結果,方法接受一個回調函數,jQuery 將遍歷查詢結果,對于每一個查詢結果對象,調用這個回調函數,并通過參數傳遞 this 和參數引用。
具體的 each 方法見 671 行函數的定義。

671 each: function( object, callback, args ) {
672 var name, i = 0, length = object.length;
673
674 if ( args ) {
if ( length === undefined ) {
for ( name in object )
if ( callback.apply( object[ name ], args ) === false )
break;
679 } else
680 for ( ; i < length; )
if ( callback.apply( object[ i++ ], args ) === false )
break;

// A special, fast, case for the most common use of each
685 } else {
686 if ( length === undefined ) {
687 for ( name in object )
if ( callback.call( object[ name ], name, object[ name ] ) === false )
break;
690 } else
691 for ( var value = object[0];
692 i < length && callback.call( value, i, value ) !== false;
value = object[++i] ){}
693 }

695 return object;
696 },
Each 的第一個參數為一個 jQuery 對象,第二個參數為處理每一個對象的回調函數,第三個參數可以為回調函數提供一個額外的參數。
注意,如果回調函返回假,那么結束遍歷過程。

674 行判斷是否提供了額外的參數,如果沒有提供,那么,執行 685行 else 語句部分的常用遍歷處理。
686 行檢查對象是否提供了 length 屬性,如果沒有,那么 687 行通過 for in 語句直接遍歷對象的所有成員,對于每一個屬性,使用 callback 進行處理,為了將當前的對象作為 this 傳遞給回調函數,使用了 call 的調用方式。
691 行和 692 行處理有 length 屬性的情況,直接通過長度進行遍歷。
如果有參數數組傳遞進來,那么,轉到 675 行進行處理。
檢查對象是否有 length 屬性,如果沒有使用 for in 語句,如果有,使用下標進行遍歷。
680 行處理有 length 屬性的情況,這時,直接通過數組的長度進行遍歷,由于參數使用了數組方式,所以通過 apply 將當前對象作為 this,其他參數作為數組進行調用。

來源:博客園

生活不易,碼農辛苦
如果您覺得本網站對您的學習有所幫助,可以手機掃描二維碼進行捐贈
程序員人生
------分隔線----------------------------
分享到:
------分隔線----------------------------
關閉
程序員人生
主站蜘蛛池模板: 欧美一区二区三区啪啪 | 91大片| 欧美中文在线观看 | 日韩成人影院在线观看 | 福利视频久久 | 欧美一区免费 | 免费一级毛片在线观看 | 国产 麻豆 日韩 欧美 久久 | 日韩欧美一区二区三区 | 精品日韩欧美 | 天天草夜夜操 | 国产乱码精品一区二区三区不卡 | 欧美高清视频在线观看 | 欧美成视频 | 青青草国产成人av片免费 | 中文字幕亚洲精品 | 亚洲免费精品 | 国产一区二区三区免费 | 精品日韩一区 | 久久精品国产免费 | 日本在线一区 | 岛国二区 | 精品中文字幕一区二区三区 | 欧美日韩一区二区三区在线视频 | 精品国产91亚洲一区二区三区www | 国产成人精品aa毛片 | 日本精品在线观看视频 | 国产精品久久久av | 国产精品观看 | 亚洲精品一区二区三区婷婷月 | 91精品一区二区 | 操操操av | 久久国产一区二区 | 日本久久一区二区 | 国产露脸精品产三级国产 | 久久成人高清 | 日韩精品一级毛片在线播放 | 亚洲欧美第一页 | 天堂av一区二区 | 久久国产亚洲精品 | 久艹精品|