• 微软原版系统

  • 一键重装系统

  • 纯净系统

  • 在线技术客服

魔法猪系统重装大师 一键在线制作启动 U 盘 PE 系统 用一键重装的魔法拯救失去灵魂的系统
当前位置:首页 > 教程 > 电脑教程

jQuery的对象构建、初始化

时间:2015年04月02日 15:36:09    来源:魔法猪系统重装大师官网    人气:7875

jQuery 作为当今最优秀的js 类库之一,必须是要花时间好好学习下的,今天正好蛋疼,读了里面一些代码,小结一下:

整个类库定义在一匿名函数中,杜绝了全局变量的产生;

将undefined 作为缺失的参数传递,防止了undefined 变量的污染;

可以看出$(...) 实际上返回的是jQuery.fn.init 对象的实例,随后将该对象的prototype 指向了jQuery.prototype (语句jQuery.fn.init.prototype = jQuery.fn),因此产生的实例共享着jQuery.prototype 里的方法和属性且实现了链式编程的操作;

最后通过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);

jQuery,的,对象,构建,、,初始化,jQuery,作为
栏目:电脑教程 阅读:1000 2023/12/27
Win7教程 更多>>
U盘教程 更多>>
Win10教程 更多>>
魔法猪学院 更多>>

Copyright © 2015-2023 魔法猪 魔法猪系统重装大师

本站发布的系统仅为个人学习测试使用,请在下载后24小时内删除,不得用于任何商业用途,否则后果自负,请支持购买微软正版软件。

在线客服 查看微信 返回顶部