欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

jQuery的初始化與對象構(gòu)建之淺析

 更新時間:2011年04月12日 00:14:37   作者:  
之前本人的工作和學(xué)習(xí)多以原生js 為主,對jQuery 一直都不是很了解,但jQuery 作為當(dāng)今最優(yōu)秀的js 類庫之一,必須是要花時間好好學(xué)習(xí)下的,今天正好蛋疼,讀了里面一些代碼
小結(jié)一下:

1.整個類庫定義在一匿名函數(shù)中,杜絕了全局變量的產(chǎn)生;
2.將undefined 作為缺失的參數(shù)傳遞,防止了undefined 變量的污染;
3.可以看出$(...) 實際上返回的是jQuery.fn.init 對象的實例,隨后將該對象的prototype 指向了jQuery.prototype (語句jQuery.fn.init.prototype = jQuery.fn),因此產(chǎn)生的實例共享著jQuery.prototype 里的方法和屬性且實現(xiàn)了鏈?zhǔn)骄幊痰牟僮鳎?
4.最后通過window.jQuery = window.$ = jQuery 將jQuery 與$ 導(dǎo)出為全局變量。

復(fù)制代碼 代碼如下:

(function(window, undefined) {
// Define a local copy of jQuery
var jQuery = (function() {
var jQuery = function(selector, context) {
// The jQuery object is actually just the init constructor 'enhanced'
return new jQuery.fn.init(selector, context/*, rootjQuery*/);
};
// ...
jQuery.fn = jQuery.prototype = {
constructor : jQuery,
init : function(selector, context, rootjQuery) {
// ...
}
// ...
};
// Give the init function the jQuery prototype for later instantiation
jQuery.fn.init.prototype = jQuery.fn;
// ...
// Expose jQuery to the global object
return jQuery;
})();
// ...
window.jQuery = window.$ = jQuery;
})(window);

相關(guān)文章

最新評論