作家
登录

jQuery的初始化与对象构建之浅析

作者: 来源:www.28hudong.com 2013-03-30 00:55:00 阅读 我要评论

小结一下: 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);

  推荐阅读

  纯JAVASCRIPT图表动画插件Highcharts Examples

What is Highcharts? 下载地址 http://www.jb51.net/jiaoben/24363.htmlHighcharts is a charting library written in pure JavaScript, offering an easy way of adding interactive charts to your web site or >>>详细阅读


本文标题:jQuery的初始化与对象构建之浅析

地址:http://www.17bianji.com/kaifa2/JS/24685.html

关键词: 探索发现

乐购科技部分新闻及文章转载自互联网,供读者交流和学习,若有涉及作者版权等问题请及时与我们联系,以便更正、删除或按规定办理。感谢所有提供资讯的网站,欢迎各类媒体与乐购科技进行文章共享合作。

网友点评
自媒体专栏

评论

热度

精彩导读
栏目ID=71的表不存在(操作类型=0)