jQuery源碼解讀三選擇器

直接上jQuery源碼截取代碼函數

// Map over jQuery in case of overwrite
_jQuery = window.jQuery,prototype

// Map over the $ in case of overwrite
_$ = window.$,code

// Define a local copy of jQuery 能夠看出建立了jQuery.fn.init這樣的一個函數返回給$,這樣就可使用$實例了
jQuery = function (selector, context) {
// The jQuery object is actually just the init constructor 'enhanced'
return new jQuery.fn.init(selector, context, rootjQuery);
},blog

//下面的這兩句,使得$實例能夠訪問jQuery.fn裏面的方法
jQuery.fn = jQuery.prototype = {源碼

init: function (selector, context, rootjQuery) {it

},
}io

// Give the init function the jQuery prototype for later instantiation
jQuery.fn.init.prototype = jQuery.fn;function

相關文章
相關標籤/搜索