本帖最后由 helloword222 于 2013-07-16 00:05:36 编辑

解决方案 »

  1.   

    只见过(function($){...})(jQuery)这种形式的
    $已经是全局变量了,又作为参数传进方法体,
    没什么区别,不知是作何用意
      

  2.   

    参数形式传递$可以用闭包将$变量保护起来
    在jquery加载一次的情况下无区别
    多次加载jquery的情况下是必要的,如:<script src='jquery1.7.js'></script>
    <script>
        (function($){
            $.fn.test1 = function(){
                alert(this.html());
            }
            $('body').click(function(){
                $(this).test1();//输出body的html
            });
        })(jQuery)
        (function(){
            $.fn.test2 = function(){
                alert(this.html());
            }
            $('body').click(function(){
                $(this).test2();//异常,test2未定义,因为$变量已被重置
            });
        })()
    </script>
    <script src='jquery1.4.js'></script>
      

  3.   

    jQuery又给你把$传递到function内部了,当做第一个参数了,免得你在内部使用jQuery,还要去全局作用域下找,少了一层变量查询,多好啊。理论上会提高效率的,实际可能差别不大。
      

  4.   

    默认情况下,用jQuery框架有$===jQuery,但是当$(function($){
       //  
       //  code  该函数内部  $===jQuery   true
       //
    })
    $(function(jQ){
       //  
       //  code  该函数内部  jQ===jQuery   true  有用到$的地方都可以换成jQ,即使$=undefined后,还可以用jQ代替
       //
    })
    这样我们调用多个js库的时候出现,即使出现$符合冲突也可以自定义其他名称代替
      

  5.   

    同意6#的说法
    由于JS变量作用域的关系,一般碰到变量JS的查找先从就近开始,比如在function中先找,找不到遍历到该function外部的function继续,直到最顶层的代码,且不论在哪个位置定义的,故如此书写节省了遍历查找的运算时间
      

  6.   

    怎么理解?
    先看下jauery的源代码
      

  7.   

    同意#6 同意#8function A(k){
    //只需明白this  是谁;
    //k  是谁
    var $ = this;
    var $$ = k;

    }
    function B(D){


    ///1=2=3//-------------1-------------------
    var $readyList = $.Deferred();
    var $rl_promise = $readyList.promise();
    $rl_promise.done(A);
    $rl_promise.done(B);
    //$readyList.resolveWith(document,[jQuery]);//--------------2------------------
    var $$readyList = $.Callbacks('once memory');
    $$readyList.add(A);
    $$readyList.add(B);
    //$$readyList.fireWith(document,[jQuery]);//-------------3-----------------
    var $$$readyList = [A,B];
    for(var i=0;i<$$$readyList.length;i++){
    $$$readyList[i].call(document,jQuery);
    }