国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

jQuery的初始化與對象構建之淺析

2019-11-20 23:51:23
字體:
來源:轉載
供稿:網友
小結一下:

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

復制代碼 代碼如下:

(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);
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 焦作市| 日喀则市| 绥江县| 五寨县| 乡城县| 镇远县| 桂东县| 海门市| 闻喜县| 开平市| 大庆市| 潜江市| 铜梁县| 余姚市| 宁津县| 庆云县| 卓资县| 滨海县| 双城市| 临洮县| 宁强县| 东兰县| 九江县| 英超| 广元市| 山阴县| 鸡东县| 浙江省| 蒙自县| 青河县| 洪洞县| 休宁县| 海盐县| 凌海市| 翁牛特旗| 探索| 台东县| 郯城县| 遂溪县| 武宣县| 荆门市|