jquery所有代码放在一个闭包中。我保留了原始注释,方便对照,有不当之处欢迎指正。 // Define a local copy of jQuery var jQuery = function( selector, context ) { // The jQuery object is actually just the init constructor 'enhanced' // jQuery对象是jQuery.fn.init函数的一个实例 return new jQuery.fn.init( selector, context ); }, // Map over jQuery in case of overwrite // 保存已有的jQuery,以防覆盖,调用noConflict会还原jQuery变量 _jQuery = window.jQuery, // Map over the $ in case of overwrite // 保存已有的$,以防覆盖 _$ = window.$, // Use the correct document accordingly with window argument (sandbox) document = window.document, // A central reference to the root jQuery(document) // jQuery(document)的核心引用 rootjQuery, // A simple way to check for HTML strings or ID strings // (both of which we optimize for) // 检测 html字符串和 id的 正则 quickExpr = /^[^<]*(<[/w/W]+>)[^>]*$|^#([/w-]+)$/, // Is it a simple selector // 简单选择器,第一字符为"."、后面不包含: # [ . ,字符 isSimple = /^.[^:#/[/.,]*$/, // Check if a string has a non-whitespace character in it // 判断字符串是否包含非空白字符 rnotwhite = //S/, // Used for trimming whitespace // /u00A0就是 rtrim = /^(/s|/u00A0)+|(/s|/u00A0)+$/g, // Match a standalone tag // /1 表示第一个()匹配 rsingleTag = /^<(/w+)/s*//?>(?:<///1>)?$/, // Keep a UserAgent string for use with jQuery.browser userAgent = navigator.userAgent, // For matching the engine and version of the browser browserMatch, // Has the ready events already been bound? // 是否已绑定判断DOM ready所需的一些事件 readyBound = false, // The functions to execute on DOM ready // 存储DOM加载完成后要执行的方法 readyList = [], // The ready event handler // ready事件处理 DOMContentLoaded, // Save a reference to some core methods // 一些方法的引用 toString = Object.prototype.toString, // hasOwnProperty判断对象自身是否包含属性,不在原型链上查找 hasOwnProperty = Object.prototype.hasOwnProperty, push = Array.prototype.push, slice = Array.prototype.slice, indexOf = Array.prototype.indexOf; 转载注明源地址!