jQuery源码研究第1天

/*!
 * jQuery JavaScript Library v1.7.2
 * http://jquery.com/
 *
 * Copyright 2011, John Resig
 * Dual licensed under the MIT or GPL Version 2 licenses.
 * http://jquery.org/license
 *
 * Includes Sizzle.js
 * http://sizzlejs.com/
 * Copyright 2011, The Dojo Foundation
 * Released under the MIT, BSD, and GPL Licenses.
 *
 * Date: Wed Mar 21 12:46:34 2012 -0700
 */

1.jQuery总体框架

(function(window,undefined){
    //工具函数 Utilities
    // 异步队列 Deferred
    //浏览器测试 Support
    // 数据缓存 Data
    // 队列 queue
    // 属性操作 Attribute
    // 事件处理 Event
    // 选择器 Sizzle
    // DOM遍历
    // DOM操作
    // CSS操作
    // 异步请求 Ajax
    // 动画 FX
    // 坐标和大小
window.jQuery = window.$ = jQuery;
})(window);

  第一对圆括号: 声明一个匿名函数;

  第二对圆括号: 调用上面声明的匿名函数,并传入window对象为参数;

可以做个实例:

<script>
(function(str){
document.write(str);
})
('aa');
</script>

网页打印出: aa;

window.jQuery = window.$ = jQuery;
这句的作用就是可以在script里面直接用'$"调用jQuery
原文地址:https://www.cnblogs.com/BigIdiot/p/2413837.html