知识点1
(function (window,undefined) {
})(window);
函数自执行防止污染全局.
传入window的作用
1. 查找变量时,window为顶层,在局部引入能节省性能?
2.可用于压缩代码?
undefined作用
1.某些浏览器,undefined可被修改.这是为了兼容修改的情况.
以下为21-94行,加上一些笔记.
var
// A central reference to the root jQuery(document)
rootjQuery,//rootjQuery = jQuery(document)
* 理解为document的jq对象?
// The deferred used on DOM ready
readyList,*老师说在dom节点时详细说
// Support: IE9
// For `typeof xmlNode.method` instead of `xmlNode.method !== undefined`
core_strundefined = typeof undefined,
* 实际上就是返回'undefined'
// Use the correct document accordingly with window argument (sandbox)
location = window.location,
document = window.document,
docElem = document.documentElement,*就是html的js对象
// Map over jQuery in case of overwrite
_jQuery = window.jQuery,
*为了防jQuery全局污染冲突
// Map over the $ in case of overwrite
_$ = window.$,
*为了防jQuery全局污染冲突
// [[Class]] -> type pairs
class2type = {},
*用来判断类型的?
// List of deleted data cache ids, so we can reuse them
core_deletedIds = [],
core_version = "2.0.3",
// Save a reference to some core methods
core_concat = core_deletedIds.concat,
core_push = core_deletedIds.push,
core_slice = core_deletedIds.slice,
core_indexOf = core_deletedIds.indexOf,
core_toString = class2type.toString,
core_hasOwn = class2type.hasOwnProperty,
core_trim = core_version.trim,
*把数组,对象,字符串原型上的一些方法用局部变量接收,
// Define a local copy of jQuery
*这个就是无new构造的精髓了,另起一篇,出门左转好无new构造.
jQuery = function( selector, context ) {
// The jQuery object is actually just the init constructor 'enhanced'
return new jQuery.fn.init( selector, context, rootjQuery );
},
// Used for matching numbers
core_pnum = /[+-]?(?:\d*\.|)\d+(?:[eE][+-]?\d+|)/.source,
// Used for splitting on whitespace
core_rnotwhite = /\S+/g,
// A simple way to check for HTML strings
// Prioritize #id over <tag> to avoid XSS via location.hash (#9521)
// Strict HTML recognition (#11290: must start with <)
rquickExpr = /^(?:\s*(<[\w\W]+>)[^>]*|#([\w-]*))$/,
// Match a standalone tag
rsingleTag = /^<(\w+)\s*\/?>(?:<\/\1>|)$/,
// Matches dashed string for camelizing
rmsPrefix = /^-ms-/,
rdashAlpha = /-([\da-z])/gi,
*上面这些正则到用的时候再回过头来看吧.
// Used by jQuery.camelCase as callback to replace()
fcamelCase = function( all, letter ) {
*这个all是用来干什么的?看不懂.
*http://www.cnblogs.com/kuangliu/p/4724424.html
*这又是个大神
*这个all是用来和replace配合的.比如str.repalce(reg,fcamelCase);
*不过还是没完全理解.
return letter.toUpperCase();
},
// The ready event handler and self cleanup method
completed = function() {
document.removeEventListener( "DOMContentLoaded", completed, false );
window.removeEventListener( "load", completed, false );
jQuery.ready();
};