jQuery1.3.2源码学习1:$是什么?jQuery是什么?
jQuery1.3.2 源码进修
本源码行使当前的 jQuery 1.3.2 版本,下载时刻 2009-4-25,下载地点:点此下载 一个函数 1 /*! 2 * jQuery JavaScript Library v1.3.2 3 * http://jquery.com/ 4 * 5 * Copyright (c) 2009 John Resig 6 * Dual licensed under the MIT and GPL licenses. 7 * http://docs.jquery.com/License 8 * 9 * Date: 2009-02-19 17:34:21 -0500 (Thu, 19 Feb 2009) 10 * Revision: 6246 11 */ 12 (function(){ 4376 })(); 省略掉中间的内容,可以看到从第 12 行到 4376 行,jQuery 代码可以简化为如上的代码。 也就是界说了一个匿名的函数,然后执行这个函数。 在这个匿名函数中完成其他的界说和操纵,这样可以停止与体系的其他函数同名造成的定名斗嘴题目。相等于一个私有的浸染域。 $ 是什么?jQuery 又是什么? 13 var 14 // Will speed up references to window, and allows munging its name. 15 window = this, 16 // Will speed up references to undefined, and allows munging its 17 name. 18 undefined, 19 // Map over jQuery in case of overwrite 20 _jQuery = window.jQuery, 21 // Map over the $ in case of overwrite 22 _$ = window.$, 23 24 jQuery = window.jQuery = window.$ = function( selector, context ) { 25 // The jQuery object is actually just the init constructor 'enhanced' 26 return new jQuery.fn.init( selector, context ); 27 }, 通过这段代码,可以看到 $,jQuery 是 window 工具上自界说的一个成员,这个成员指向了一个匿名函数,往后可以通过window 工具的 $ 可能 jQuery 来行使这个函数。 这个函数返回了一个通过 jQuery.fn.init 函数界说的工具。声名通过 jQuery 获得的工具着实是一个 jQuery.fn.init 函数建设的工具,那么,往后通过 jQuery.fn.init 的原型界说的函数可能属性都可以被通过 jQuery 建设的工具来行使。
jQuery.fn 是什么? 35 jQuery.fn = jQuery.prototype = { 538 }; 从 35 行到 538 行,为 jQuery.fn 的界说,jQuery.fn 就是 jQuery 所指向的函数的原型工具。以是在 jQuery 的原型上界说的函数就可以通过 jQuery.fn 来行使了。 而上边的 jQuery.fn.init 就是 jQuery 函数原型工具上的一个函数。 (编辑:河北网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |